context.random_weight(params)

Generate a random weight.

Arguments:

  • params: a string that controls the random generation of the weight such as min and max range value, or elements of the weightset with associated densities.

See also:

Examples

In [1]:
import os
# This trick ensures that we always use the same random seed,
# hence running this documentation always gives the same result.
os.environ['VCSN_SEED'] = '1'
import vcsn
ctx = vcsn.context('lal_char(abc), z')
In [2]:
print([ctx.random_weight() for _ in range(10)])
[-404620562, -133711905, -1579004998, -1944672731, -1946129057, -15198492, 676943009, -81133257, 2084672536, 1275731771]

Densities associated with elements form a Bernoulli distribution with the rest of the weightset's elements.

For example, here "0" has 1 in 2 chances to appear, otherwise a uniform distribution is performed on the weightSet, in the range [0-10].

In [3]:
print([ctx.random_weight('0=0.5,min=0,max=10') for _ in range(20)])
[0, 9, 8, 0, 0, 0, 0, 0, 2, 0, 0, 7, 1, 0, 0, 8, 0, 8, 8, 0]