In [9]:
from theano.tensor.shared_randomstreams import RandomStreams
from theano.printing import pp
from theano import function

In [2]:
srng = RandomStreams(seed=234)
rv_u = srng.uniform((2,2))
rv_n = srng.normal((2,2))

In [7]:
print pp(rv_n)
print pp(rv_n)


RandomFunction{normal}(<RandomStateType>, int32([TensorConstant{2}, TensorConstant{2}]), TensorConstant{0.0}, TensorConstant{1.0})
RandomFunction{normal}(<RandomStateType>, int32([TensorConstant{2}, TensorConstant{2}]), TensorConstant{0.0}, TensorConstant{1.0})

In [10]:
f = function([], rv_u)
g = function([], rv_n, no_default_updates=True)    #Not updating rv_n.rng

In [20]:
print "f() is {}".format(f())
print 
print "g() is {}".format(g())


f() is [[ 0.28179047  0.23616647]
 [ 0.5958365   0.1385743 ]]

g() is [[ 0.37328447 -0.65746672]
 [-0.36302373 -0.97484625]]

In [21]:
nearly_zeros = function([], rv_u + rv_u - 2 * rv_u)

In [24]:
nearly_zeros()


Out[24]:
array([[ 0.,  0.],
       [ 0.,  0.]])

In [25]:
rng_val = rv_u.rng.get_value(borrow=True) # Get the rng for rv_u rng_val.seed(89234) # seeds the generator rv_u.rng.set_value(rng_val, borrow=True) # Assign back seeded rng

In [29]:
rng_val


Out[29]:
<mtrand.RandomState at 0x107215710>

In [31]:
state_after_v0 = rv_u.rng.get_value().get_state()
# this affects rv_u's generator v1 = f() rng = rng.get_value(borrow=True) rng.set_state(state_after_v0) rv_u.rng.set_value(rng, borrow=True) v2 = f() # v2 != v1

In [32]:
state_after_v0


Out[32]:
('MT19937', array([1412837902, 4087756582,  516309042, 1364072208, 1090621429,
        4112181791, 3626575279, 1669722016, 3008290917,  852339364,
         138280172,  165820123, 2327577011, 3079128434, 3457976983,
         359398700, 1807233986, 1274846374, 4117684190,   73832659,
        1478997809, 1174043298, 1741287282, 2408080718, 2281248458,
         932100177, 3771617988, 1600467228,  924198853, 4068010514,
        2587713894, 3433167301, 1613211556, 2120429277,  397803828,
        1420342703,  498076466,  915436930, 3968997384, 1080010303,
        3772081571, 3010457279, 2416405684, 3446465340, 3562542605,
        1819353986, 3800663786,  915703320, 2059339361, 4125682097,
        3511670932,  516487005,  839137542, 3788010305, 3224581901,
         941172982, 2777973816, 2028991983, 1416998551, 3402826840,
        1706339450,   64970340, 1156665240, 1332620248, 1066760937,
        2073534949, 1046328115, 3780476516, 1939087946, 4162625085,
         269457214, 2946549107, 2415322410,  122216919, 4284949092,
        3931977509, 1232741786, 3962103520, 2467239141, 1457000662,
        2596712546, 2319750987, 3564233040, 4187982969,  716710529,
        1635315776,  932314278,  798657003, 3728875315, 1979249970,
        2854781471, 4144158891, 1874767531, 3179091202, 1453140231,
        4104657811, 1141787777,  576525996,  111151510,  363590525,
         548832472,  769198274, 3179968677, 3818150943, 1985647709,
        2312394400, 3238056780, 3535874624,   26674961, 1982425085,
         179526683,  524607122,  733786888, 1479839416, 3112831309,
        2663089241, 3164611155, 3794299985, 3309069440, 2448700555,
        1413605274, 2944283910, 2934808181,  560951660, 3430501763,
         134472123, 1744554810, 3901983634, 4260991572, 2026804764,
         599412781, 1677821654, 2970357069,  274568852, 4029216823,
        2163308429,  923404741, 3060758440, 3188078736,  589482521,
         714322363,  591446418, 2224572094, 3261582840, 3734124780,
        2518244455, 3164126701, 2645926636, 2369908400, 1822787024,
        4061149396,  939368302, 3110123697, 3062841555, 2504793946,
         153656410,  897374583, 3963596744,  100650606,  726856439,
        3043251727, 3696952182, 3033025986,  600137326,  596338481,
        2349588735,  208351545, 2370206405, 3881572849, 1487701115,
        2061074391, 1934520009, 2639386111,   38641262, 1124173263,
         609603763, 2918324016, 2392772417, 2434206835,  683879474,
         325978279, 1769495085, 1161205011, 3719825126, 2198578744,
         826291772, 1550646588, 1969142839,   13804749,  436642740,
        2199983786, 1581160537, 3930022013, 3542172581, 4248999801,
        3574780596, 2774672601, 1416736027, 1690641351, 1268367246,
        3186632028, 3014657937, 3812829988,   63083448, 2329771683,
        3174781836, 3855289781,  927023402,   20655977, 2880261689,
        2023853847,  891739105, 2131595572, 2699019987, 2642204749,
        1518960179, 1162519712, 2934363193, 3065378916, 1154231621,
        4036082481, 1148973407, 1009256058,  102565122,  503854828,
        3516132618, 3303814558,  639761349, 4015469082, 1498019510,
        3653042504, 3826419779,   66870972, 3768255694, 1581987533,
         313766547, 2716611032, 2804185931, 3207109835, 2368363152,
        1703564111, 1847407645, 2515691761, 3868455915,  566761734,
        1945727564,  469045596, 1486650326, 3319971042, 2978889768,
        2670986471, 2781736929, 1642673298, 2461141453, 1752150435,
        3613305138,  499854688, 3061951908, 3687032443,  828529273,
        2702211660, 3934432907, 2374651832, 2424894963, 1261067248,
         165808961, 4117415507, 3777841030, 1514267354, 3613582842,
        2127542702, 2584873609, 4049762241,   86428185, 3504973197,
        1317318877, 3765014744, 4070756204, 1727630374, 2348271132,
        1945707995,   46761409, 1577128108,  179052069, 3403150376,
        1154881936, 1902199253, 1811744656, 2711675737,  359315896,
        4068057142, 1053026574, 2366071146,  322081552, 3780530289,
         350339122, 3608987810, 2833067747, 2051365992, 1840052468,
        2474286067,  264515920, 1502144692,    7148633, 1430039480,
        2193707321, 3977833580, 2255323409,  409610861,  909136298,
        1903485074, 2560486284, 4086313705, 4136292667,  908962737,
        2774687414, 1183334136,  439973059, 1167020730,  135222752,
        2629376488, 3392769661, 4189814270,  593852863,  488825447,
        2359575845,  830919823, 2892840407, 1592227086, 1864094786,
        4237919087, 2135327627,  527173739, 1355678894, 4210298667,
        3648583138, 1643580234,  358387655, 2337225784, 2383604050,
        3351415364, 1800909141, 4137137445, 1777508899, 3762801979,
        3496873471, 1184270647, 2449156175, 2429291349,   84994442,
        4161337351,   46898071,  253630401,  518838530, 3707135726,
        1480913371, 3905161601, 3300042022, 3377411934, 3601039599,
         417189573, 3493185949, 2486378743,  987284509,  710674841,
        1070944000, 1587998505, 2227576894, 3327962578, 3191694538,
        2276079469, 2449156594,  561980200, 3411787805, 2611759090,
        2733088034, 2065892825, 2430399281, 2060756234, 3009361539,
         638463092,  737105740, 3428057890, 2996803837, 2595504223,
        4018007824, 2539379822, 3391891402, 2727184575, 1848512064,
        2026855084, 1331583874, 3163448297, 3188900547,  653230404,
        3856012077, 4260245814,  736993553, 2328083036, 3288883360,
        4215337583,  547225099,  923643235, 2149573866, 2177133374,
        3911932146, 1447737292, 3101525708, 3138482631, 3593894820,
        3340151406, 2617080910, 2647642559, 1673873703, 1128921886,
        3448067160,  688070401,  874427289, 2361677012, 1547920252,
        1249326610,  547487572, 4057271732, 1213717997, 2874898914,
          16662783,  126079883, 4087801654, 1636454211,  981046718,
         277594235, 2731219300, 3757506341, 2079189074, 1009720718,
        2006644122, 3708151614, 4254927768,   32367359, 2308883490,
         858672165, 1710979013, 3877381084,  467561107, 1501722750,
        2729007283, 3338344744,  828563679,  351260380, 1227859793,
          91118473, 2045383096, 3976646835,  386929260,  763659410,
        4152819501, 3058735963, 3514238679, 1647845692, 3345147262,
        3613960644, 3812942489, 2218593522,  437896599,  161601068,
        4102760237,  911463144,  655123239, 4138026288,  315757625,
        2877154215,  108069870,  170419904, 2343464280, 1647161553,
        1508545118, 2905898392, 2943976376, 4166030425,   93316479,
        2161468649,  475425833, 2892642633, 2393638036, 2544999224,
         390414386,  956198573, 2778871508,  437191685, 2370171986,
         292232043, 2384430697, 1665788653,   53876070,  219470071,
         720673497, 3246939168, 1271481429, 2946254394, 1936856149,
         533303133, 3518635330, 2652645443, 1582583892, 1289536264,
        1326188002, 2500772376, 1954127689, 3966137059, 1886510204,
         895745511, 1709586379, 3290905315, 4150257029, 1891528335,
        4245382273, 3190110301, 2658508924, 1446440771, 1865300999,
        3393630316,  197613071, 2233550695, 1100280151, 3181015976,
        2103750390, 2234554601, 4290323204, 2083870105, 4029629027,
        4112954128, 1577926272, 1211334753, 1018603816, 2464292852,
         882840584, 1674884761, 1007819093, 1075894648, 1391370625,
        1110992549,   18877701, 2666168432, 3458535879,  875810272,
        3988810231, 3740751919, 1762844494,  656066760, 3903295259,
        2227612428, 1130875250, 1196377602, 3564596308,  247710625,
        1706233805,  675533329, 3116622366, 4138391800, 3595300543,
        2093457292,  406063726,  451731325, 3303496345, 2982152654,
        2950895025, 3706919204, 4291792878, 1099123380, 1247972206,
        2157177882, 4089670375,  223362415, 2882411391,  615705890,
        2640427279, 3262073682,  416108777, 3203460670, 1933873108,
         458545692, 3856674583,  392715637, 3977197131, 1499680815,
        1186094788, 4119391230, 4264946994, 1095700140, 1709141516,
        2995125657, 4293826842, 1251606668, 3944369121, 1269506870,
        1192678818, 2830564642, 3699006581, 1959410213,  290175100,
        3059960693,  224500426, 3269831356, 2183887773, 1690545694,
        1015643982,  249955423, 2024239502, 3071621441,  914696671,
        2027725858, 1132035017, 2231938653,  889246455,  871073059,
        2875629117, 3649030881, 2027634247, 3459022769, 1661505375,
        3698008114, 2495837797,  118389792, 3623168049], dtype=uint32), 64, 0, 0.0)