Python random getstate














































Python random getstate



 Python random : getstate() 



This article demonstrates how to use random.getstate() function .

The getstate() method in python is used to capture the state and returns an object of the random number generator with the current state.


Syntax :

random.getstate()

Parameters : 
Not require any parameter value.

Return Value :
Returns an object with the current internal state of the random number generator.


Here are some examples of Python random getstate() Method:

1.
#importing random module
import random
z = random.getstate() #Use of getstate() method
print("Output of use of getstate : ",z)
Output - 
Output of use of getstate :  (3, (2147483648, 2013501805, 410957261, 2687417943, 1060650831, 130867982, 1892937105, 991597106, 711620676, 3466090128, 1074469361, 2125023479, 2727347847, 1729337014, 1180253130, 3252301545, 642867888, 4204653624, 1397497658, 545779315, 24998153, 3107030577, 1503568520, 3476435233, 1494971334, 2028555928, 59446950, 3248880941, 2992396648, 3769267026, 942115706, 1832916376, 3422423103, 865516629, 1425035767, 4163930666, 3434250140, 3806605073, 2676096, 1414890371, 1950380276, 3253478510, 2098443219, 555361498, 3682735951, 2558529897, 3564052709, 2282336671, 900153716, 1914845299, 3083738534, 1148770503, 3306716174, 1466897912, 2585185673, 1778164369, 459063320, 4173494061, 1463308098, 2755521070, 2190713548, 1880298700, 4023946597, 776252410, 1034507554, 3855673162, 1993581786, 2213177222, 2446067557, 1011011889, 4185884633, 1315404004, 1002110764, 76845374, 3970719317, 1810282524, 1488327854, 2869934080, 1183827004, 652290665, 1801514101, 3859384614, 222419336, 793859219, 1648986098, 2201849637, 2366845422, 558264206, 3449291454, 205376146, 1089499468, 3501505685, 3084511258, 166236957, 2970454566, 692570046, 2883963181, 2568248471, 3172396669, 425609192, 1585571121, 3553151999, 972308191, 1798502185, 1983897303, 2468643973, 2426482366, 383448272, 3125985443, 1069713203, 3846410727, 3350701402, 452453013, 1738770081, 1895437355, 282774212, 683852294, 2263954992, 1965336964, 1105412953, 2167774503, 3595861493, 621433385, 3089629091, 1711481425, 2883934264, 3253832148, 2765900900, 69656322, 517473461, 327531720, 1174330268, 3529823598, 418745182, 2279292512, 2181466413, 97931715, 638140934, 1196508713, 2678673539, 1557113616, 460140982, 1782235478, 2704360605, 2053316851, 1731624283, 3941824606, 279391301, 3628601112, 2786345822, 1912676303, 2472919245, 3316539042, 1617413889, 3400198792, 3223206671, 3141541446, 4133572146, 3673783417, 2231940223, 3430614757, 1816536374, 1829328860, 2038557758, 3302209724, 2298057926, 134557177, 3994495046, 2316907598, 373235581, 1381866802, 4985905, 1974268961, 1687434128, 1461065573, 3795301448, 2250995937, 3860147636, 3106782725, 1493976052, 3802871710, 4154439158, 344011198, 1793363093, 595036815, 1093242623, 552491392, 857113817, 1410955738, 1532957246, 1516735808, 1221656118, 263139836, 665123545, 3224065477, 2161657556, 3460761396, 1615675943, 2980586084, 1773555249, 4120761452, 1517519751, 1270127235, 2500901079, 1007991773, 3245320908, 2720233007, 3152061685, 1729209523, 2427301857, 1853541606, 2284269602, 1973673314, 370471575, 56090187, 1740658727, 682979597, 135913152, 581978134, 2711972448, 3594096696, 140861626, 3724761944, 1357671069, 840836322, 1113233090, 1122723903, 397526703, 902528688, 2371195464, 2329426672, 3713558079, 2331362494, 2323046080, 4251501010, 1594483130, 436045730, 3873298106, 2906972549, 2095027378, 3525940877, 3593748128, 2613502599, 1972599694, 2442804808, 3569665975, 2558159171, 3293327154, 2053645560, 3613502207, 1917873304, 3136494020, 504471195, 339454507, 3019601552, 2764569901, 1881661939, 1133976634, 468566099, 3574149719, 3407944785, 624039606, 557865556, 2056313125, 3661632522, 2083340975, 1011520595, 1557059184, 1446522361, 1868252443, 2338897569, 3915922661, 2350308650, 691514005, 1758470265, 361506527, 3070944467, 3683211966, 349456489, 3231843102, 3909169574, 4162784339, 1966161338, 904778046, 1721754066, 2688933950, 2692904728, 3003452002, 909434756, 304616663, 3556833687, 1662945713, 1780873856, 2843460645, 2118754294, 2355044787, 961256430, 2232382576, 1373159098, 2860311681, 1527985603, 1593349064, 2677238438, 150720936, 4074167133, 2529881251, 496060390, 3202532987, 3969281558, 2463732959, 1951959790, 1935315480, 3069622835, 3387944181, 729745552, 3073678575, 172101817, 2238591806, 1297225974, 3576821790, 3511862059, 162326483, 1880423590, 1550110190, 3480732838, 3162950747, 2569411329, 230865898, 1320355671, 501372135, 1819115905, 333443294, 3854442344, 817266223, 1580751271, 3595062788, 3753598054, 2592113882, 4164507953, 2396899832, 4207044993, 186669776, 2513522978, 1405280599, 3916588357, 1052941141, 1589097693, 2311355867, 2660850818, 2557672757, 205416873, 493904137, 3774711521, 2492524866, 3355586621, 2271180777, 2808988384, 1327606617, 172976342, 2662807310, 3160433930, 2020903718, 2833577923, 2172701759, 3055308641, 1508499941, 1457372746, 1414141660, 2286526879, 3955924902, 310473244, 3242676412, 2589172524, 3609432560, 2181835981, 3173584776, 2490752930, 3973058850, 1439586348, 2572147834, 2186689561, 2595150382, 2700355057, 1732043270, 3740101150, 2332534840, 1100563503, 4239663376, 3892940855, 3216195883, 2655611778, 3867264587, 406863407, 2479275581, 4255405033, 1079707587, 661028581, 1999563073, 191991235, 3296218100, 2890361314, 28964187, 3120239716, 1094820032, 88799794, 461431045, 4069270885, 4138280603, 1837188266, 2639840355, 359276272, 3262314613, 1917281262, 2926062498, 595954031, 374624379, 4162906474, 2692550963, 1608098519, 1371907106, 245445035, 845646054, 2947477155, 4063046253, 3088206923, 3601986145, 2818497136, 982017517, 2711092855, 2557872608, 1668655288, 1127606762, 90384396, 2608346362, 3950304626, 562163443, 686890061, 1955406360, 458156989, 2038237030, 3247090248, 3081599249, 1560954583, 3840928842, 2221623662, 1182596297, 415884296, 2787556595, 4103662525, 490047956, 2207849801, 4005131669, 2943429572, 1263816413, 900770023, 1578489513, 3002386309, 2118970069, 1552976557, 2184372963, 1717966674, 2108801629, 4151519691, 540828058, 3532751533, 2850093621, 3751559374, 623093258, 3236670284, 1523626940, 1758900753, 4289273403, 2668448145, 825284897, 154640327, 2588462467, 2275998897, 3506334281, 1917506476, 3812031632, 1060852660, 34407228, 1893603210, 94239181, 1933157660, 1575871210, 3917436189, 2574996917, 740078594, 33351862, 942656881, 649051293, 151214353, 636650366, 2255496768, 1795161890, 738258688, 2787989166, 1063821195, 216115334, 3729683115, 774408642, 1636715632, 2589473991, 2599515309, 156147633, 201903005, 1773367714, 3512733510, 2870680022, 2571807154, 861473876, 1559342570, 899132907, 2454123979, 3037835961, 1792896144, 2804711629, 2688144832, 2006472744, 1280945969, 4059071497, 465808378, 1791748344, 3066577368, 357473029, 902874422, 555456485, 4045302498, 3854709921, 912670012, 3838447363, 2768808508, 1972473901, 2723264319, 176439, 3313207433, 1414965319, 1906442899, 3346163556, 2930578850, 2825504374, 2811363218, 719938279, 2807830524, 3822582628, 78544188, 712632308, 949813481, 1195973547, 1847952752, 2223738555, 2180037614, 1857701102, 534881041, 883783444, 3228460250, 1607018133, 2223758138, 857374730, 490874595, 893723797, 3375049418, 3247844818, 1159317176, 1965688443, 4020902237, 2419867458, 3127274475, 2125552528, 3789498845, 914736790, 1579717433, 2641094204, 3622960348, 2837081554, 1277024523, 2985937081, 133336803, 3310680893, 4259759224, 3327189525, 1342465489, 2845140771, 2532220690, 3295644934, 2908984934, 751087121, 454039324, 1850200842, 2851693859, 3539046376, 882890663, 2385151472, 4253171397, 3495302598, 4146409135, 1345416340, 2525195972, 44537047, 3588461077, 4004367229, 2677823913, 1825987488, 1778893391, 3795189656, 3097977982, 2095119060, 3147374127, 965401316, 566536321, 581833498, 1543734622, 954920803, 830061282, 190959387, 1453899897, 2578794789, 1323872337, 3516985182, 3481605360, 1148716273, 503238766, 1985147440, 624), None)

2.
#importing random module
import random 
    
list1 = [123456
    
# Get the state 
state = random.getstate() 

# prints a random value from the list 
print(random.choice(list1)) 
    
# Set the state 
random.setstate(state) 

# prints the same random value 
# from the list 
print(random.choice(list1))
Output :
4
4

   *******END OF ARTICLE*******



More Articles of Vishal Lodhi:

Name Views Likes
Python string zfill 92 0
Python string swapcase 80 0
Python string title 84 0
Python string startswith 89 0
Python string replace 134 0
Python string translate 72 0
Python string rpartition 76 0
Python string partition 66 0
Python string splitlines 95 0
Python string rsplit 65 0
Python string split 65 0
Python string rindex 73 0
Python string rfind 93 0
Python string upper 68 0
Python string lower 67 0
Python string maketrans 75 0
Python string strip 72 0
Python string rstrip 75 0
Python string lstrip 71 0
Python string rjust 81 0
Python string ljust 81 0
Python string len 70 0
Python string join 63 0
Python string casefold 68 0
Python string isprintable 70 0
Python string encode 68 0
Python string isdecimal 73 0
Python string isidentifier 65 0
Python string isupper 62 0
Python string istitle 69 0
Python string isspace 82 0
Python string isnumeric 87 0
Python string isdigit 68 0
Python string islower 72 0
Python string isalpha 82 0
Python string isalnum 78 0
Python string index 78 0
Python string find 82 0
Python string expandtabs() 73 0
Python string endswith 77 0
Python string count 72 0
Python string capitalize 64 0
Python string center 74 0
Python string Introduction 89 0
Python string Template 128 0
Python string Formatter 122 0
Python string printable 169 0
Python string whitespace 124 0
Python string punctuation 84 0
Python string octdigits 75 0
Python string hexdigits 89 0
Python string digits 68 0
Python string ascii_letters 260 0
Python string ascii_lowercase 116 0
Python string ascii_uppercase 121 0
How to Create Download Manager in Python 394 0
Python random weibullvariate 150 0
python random paretovariate 121 0
Python random vonmisesvariate 151 0
Python random normalvariate 158 0
Python random lognormvariate 102 0
Python random gauss 104 0
Python random gammavariate 112 0
Python random expovariate 165 0
Python random betavariate 148 0
Python random triangular 103 0
Python random uniform 129 0
Python random random 108 0
Python random sample 160 0
Python random shuffle 168 0
Python random choices 189 0
Python random choice 151 0
Python random randint 134 0
Python random randrange 182 0
Python random getrandbits 127 0
Python random setstate 121 0
Python random getstate 161 0
Python random seed 158 1
Python random Introduction 159 0

Comments