Changing Python Random Sample Algorithm

Is it possible to set up an internal random module selection algorithm in Python to change the default selection and select randint from normal to some other distribution package during program execution (for example, to tinker with a seed or state), but then just use the randint and selection functions?

For example, I would like some left distorted samples.

If so, could you advise how to do this.

+4
source share
1 answer

The numpy library provides many different distributions and the random library provides several options

, , , . , choice random.random(),

def choice(self, seq):
        """Choose a random element from a non-empty sequence."""
        return seq[int(self.random() * len(seq))]  

random . , , .

, __builtin__ ,

from numpy.random import beta
from random import gauss

def choice(seq):
        return seq[int(beta() * len(seq))]  

, .

Random ,      :     : random(), seed(), getstate() setstate().     , getrandbits(), randrange()      .

BetaRandom, , , imo, ( )


, numpy setstate ,

* TessellatingHeckler

+4

Source: https://habr.com/ru/post/1627050/


All Articles