Beispiel #1
0
 def f(x, y):
     x = r_uint(x)
     y = r_uint(y)
     rnd = Random(x)
     rnd.init_by_array([x, y])
     rnd.jumpahead(intmask(y))
     return float(rnd.genrand32()) + rnd.random()
Beispiel #2
0
 def f(x, y):
     x = r_uint(x)
     y = r_uint(y)
     rnd = Random(x)
     rnd.init_by_array([x, y])
     rnd.jumpahead(intmask(y))
     return float(rnd.genrand32()) + rnd.random()
Beispiel #3
0
 class rand(object):
     def seed(self, seed):
         self.r = Random(seed)
     def randint(self, a, b):
         r32 = intmask(self.r.genrand32())
         r = a + r32 % (b - a)
         return intmask(r)
Beispiel #4
0
def test_numbers():
    rnd = Random(1000)
    nums = [rnd.genrand32() for i in range(14)]
    assert nums == [
        2807145907, 882709079, 493951047, 2621574848, 4081433851, 44058974,
        2070996316, 1549632257, 3747249597, 3650674304, 911961945, 58396205,
        174846504, 1478498153
    ]
Beispiel #5
0
def rrandom_example():
    rnd1 = Random()

    print rnd1.genrand32()  # get a 32-bit random number
    print rnd1.random()  # get a float random number x, 0.0 <= x < 1.0

    seed = 1546979228
    rnd2 = Random(seed)  # set a seed
    print rnd2.random()

    print rnd1.state  # you can access the internal state of the generator

    # change the internal state to one different from and likely far away from
    # the current state, n is a non-negative integer which is used to scramble
    # the current state vector.
    n = 10
    rnd1.jumpahead(n)
    rnd1.random()
Beispiel #6
0
class rand(object):
    def seed(self, seed):
        self.r = Random(seed)
    def random(self):
        return self.r.random()
    def randint(self, a, b):
        r32 = intmask(self.r.genrand32())
        r = a + r32 % (b - a)
        return intmask(r)
Beispiel #7
0
def test_numbers():
    rnd = Random(1000)
    nums = [rnd.genrand32() for i in range(14)]
    assert nums == [2807145907, 882709079, 493951047, 2621574848, 4081433851,
            44058974, 2070996316, 1549632257, 3747249597, 3650674304,
            911961945, 58396205, 174846504, 1478498153]