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:
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')
print([ctx.random_weight() for _ in range(10)])
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].
print([ctx.random_weight('0=0.5,min=0,max=10') for _ in range(20)])