[{"data":1,"prerenderedAt":2162},["ShallowReactive",2],{"doc-\u002Fstandard-library\u002Fpython-random-module-overview":3},{"id":4,"title":5,"body":6,"description":2155,"extension":2156,"meta":2157,"navigation":88,"path":2158,"seo":2159,"stem":2160,"__hash__":2161},"content\u002Fstandard-library\u002Fpython-random-module-overview.md","Python random Module Overview",{"type":7,"value":8,"toc":2115},"minimark",[9,13,22,25,41,44,56,61,191,202,206,212,215,229,236,241,255,261,272,276,282,298,301,315,319,325,332,346,376,379,388,391,397,411,449,451,460,463,470,476,483,549,551,565,568,591,596,602,605,672,674,683,686,723,725,734,741,747,753,835,837,889,892,898,905,981,983,1005,1011,1017,1023,1094,1096,1125,1132,1138,1142,1148,1177,1180,1383,1387,1396,1399,1403,1417,1423,1436,1440,1445,1451,1461,1488,1491,1502,1509,1516,1519,1561,1566,1639,1646,1649,1716,1719,1729,1735,1738,1797,1807,1810,1877,1880,1884,1887,1922,1929,1933,1936,1993,1997,2001,2007,2016,2022,2030,2040,2043,2050,2056,2063,2069,2073,2102,2111],[10,11,5],"h1",{"id":12},"python-random-module-overview",[14,15,16,17,21],"p",{},"The ",[18,19,20],"code",{},"random"," module is a built-in Python module for working with pseudo-random values.",[14,23,24],{},"Beginners often use it to:",[26,27,28,32,35,38],"ul",{},[29,30,31],"li",{},"generate random numbers",[29,33,34],{},"choose a random item from a list",[29,36,37],{},"shuffle a list",[29,39,40],{},"pick several random items",[14,42,43],{},"It is useful for games, simple scripts, testing, and practice programs.",[14,45,46,47,51,52,55],{},"It is ",[48,49,50],"strong",{},"not"," the right tool for passwords, secure tokens, or anything security-related. For that, use the ",[18,53,54],{},"secrets"," module instead.",[57,58,60],"h2",{"id":59},"quick-example","Quick example",[62,63,68],"pre",{"className":64,"code":65,"language":66,"meta":67,"style":67},"language-python shiki shiki-themes material-theme-lighter github-light github-dark","import random\n\nprint(random.randint(1, 10))\nitems = [\"apple\", \"banana\", \"cherry\"]\nprint(random.choice(items))\n","python","",[18,69,70,83,90,125,170],{"__ignoreMap":67},[71,72,75,79],"span",{"class":73,"line":74},"line",1,[71,76,78],{"class":77},"sVHd0","import",[71,80,82],{"class":81},"su5hD"," random\n",[71,84,86],{"class":73,"line":85},2,[71,87,89],{"emptyLinePlaceholder":88},true,"\n",[71,91,93,97,101,104,107,110,112,116,119,122],{"class":73,"line":92},3,[71,94,96],{"class":95},"sptTA","print",[71,98,100],{"class":99},"sP7_E","(",[71,102,20],{"class":103},"slqww",[71,105,106],{"class":99},".",[71,108,109],{"class":103},"randint",[71,111,100],{"class":99},[71,113,115],{"class":114},"srdBf","1",[71,117,118],{"class":99},",",[71,120,121],{"class":114}," 10",[71,123,124],{"class":99},"))\n",[71,126,128,131,135,138,142,146,148,150,153,156,158,160,162,165,167],{"class":73,"line":127},4,[71,129,130],{"class":81},"items ",[71,132,134],{"class":133},"smGrS","=",[71,136,137],{"class":99}," [",[71,139,141],{"class":140},"sjJ54","\"",[71,143,145],{"class":144},"s_sjI","apple",[71,147,141],{"class":140},[71,149,118],{"class":99},[71,151,152],{"class":140}," \"",[71,154,155],{"class":144},"banana",[71,157,141],{"class":140},[71,159,118],{"class":99},[71,161,152],{"class":140},[71,163,164],{"class":144},"cherry",[71,166,141],{"class":140},[71,168,169],{"class":99},"]\n",[71,171,173,175,177,179,181,184,186,189],{"class":73,"line":172},5,[71,174,96],{"class":95},[71,176,100],{"class":99},[71,178,20],{"class":103},[71,180,106],{"class":99},[71,182,183],{"class":103},"choice",[71,185,100],{"class":99},[71,187,188],{"class":103},"items",[71,190,124],{"class":99},[14,192,193,194,197,198,201],{},"Use ",[18,195,196],{},"randint()"," for a random whole number in a range, and ",[18,199,200],{},"choice()"," to pick one item from a list.",[57,203,205],{"id":204},"what-the-random-module-is","What the random module is",[14,207,208,209,211],{},"Python’s ",[18,210,20],{}," module is part of the standard library, so you do not need to install anything.",[14,213,214],{},"It gives you functions for:",[26,216,217,220,223,226],{},[29,218,219],{},"random numbers",[29,221,222],{},"random choices from sequences",[29,224,225],{},"random sampling",[29,227,228],{},"shuffling lists",[14,230,231,232,235],{},"The values are ",[48,233,234],{},"pseudo-random",". That means they are produced by an algorithm, but they behave randomly enough for most beginner programs.",[14,237,193,238,240],{},[18,239,20],{}," for:",[26,242,243,246,249,252],{},[29,244,245],{},"small games",[29,247,248],{},"classroom examples",[29,250,251],{},"simple automation",[29,253,254],{},"testing with sample data",[14,256,257,258,260],{},"Do ",[48,259,50],{}," use it for:",[26,262,263,266,269],{},[29,264,265],{},"passwords",[29,267,268],{},"authentication tokens",[29,270,271],{},"security-sensitive code",[57,273,275],{"id":274},"when-beginners-use-it-most","When beginners use it most",[14,277,278,279,281],{},"Beginners usually use ",[18,280,20],{}," when they want to:",[26,283,284,287,289,292,295],{},[29,285,286],{},"pick a random number in a range",[29,288,34],{},[29,290,291],{},"shuffle a list into a new order",[29,293,294],{},"pick multiple random items",[29,296,297],{},"create simple game behavior",[14,299,300],{},"For example, you might:",[26,302,303,306,309,312],{},[29,304,305],{},"roll a die",[29,307,308],{},"choose a random student name",[29,310,311],{},"shuffle quiz questions",[29,313,314],{},"build a number guessing game",[57,316,318],{"id":317},"functions-to-know-first","Functions to know first",[14,320,321,322,324],{},"These are the most common functions in the ",[18,323,20],{}," module.",[326,327,329],"h3",{"id":328},"randomrandom",[18,330,331],{},"random.random()",[14,333,334,335,338,339,342,343,106],{},"Returns a floating-point number from ",[18,336,337],{},"0.0"," up to but ",[48,340,341],{},"not including"," ",[18,344,345],{},"1.0",[62,347,349],{"className":64,"code":348,"language":66,"meta":67,"style":67},"import random\n\nprint(random.random())\n",[18,350,351,357,361],{"__ignoreMap":67},[71,352,353,355],{"class":73,"line":74},[71,354,78],{"class":77},[71,356,82],{"class":81},[71,358,359],{"class":73,"line":85},[71,360,89],{"emptyLinePlaceholder":88},[71,362,363,365,367,369,371,373],{"class":73,"line":92},[71,364,96],{"class":95},[71,366,100],{"class":99},[71,368,20],{"class":103},[71,370,106],{"class":99},[71,372,20],{"class":103},[71,374,375],{"class":99},"())\n",[14,377,378],{},"Possible output:",[62,380,382],{"className":64,"code":381,"language":66,"meta":67,"style":67},"0.472918374\n",[18,383,384],{"__ignoreMap":67},[71,385,386],{"class":73,"line":74},[71,387,381],{"class":114},[14,389,390],{},"Use this when you want a random decimal value.",[326,392,394],{"id":393},"randomrandinta-b",[18,395,396],{},"random.randint(a, b)",[14,398,399,400,403,404,407,408,106],{},"Returns a random whole number from ",[18,401,402],{},"a"," to ",[18,405,406],{},"b",", ",[48,409,410],{},"including both ends",[62,412,414],{"className":64,"code":413,"language":66,"meta":67,"style":67},"import random\n\nprint(random.randint(1, 6))\n",[18,415,416,422,426],{"__ignoreMap":67},[71,417,418,420],{"class":73,"line":74},[71,419,78],{"class":77},[71,421,82],{"class":81},[71,423,424],{"class":73,"line":85},[71,425,89],{"emptyLinePlaceholder":88},[71,427,428,430,432,434,436,438,440,442,444,447],{"class":73,"line":92},[71,429,96],{"class":95},[71,431,100],{"class":99},[71,433,20],{"class":103},[71,435,106],{"class":99},[71,437,109],{"class":103},[71,439,100],{"class":99},[71,441,115],{"class":114},[71,443,118],{"class":99},[71,445,446],{"class":114}," 6",[71,448,124],{"class":99},[14,450,378],{},[62,452,454],{"className":64,"code":453,"language":66,"meta":67,"style":67},"4\n",[18,455,456],{"__ignoreMap":67},[71,457,458],{"class":73,"line":74},[71,459,453],{"class":114},[14,461,462],{},"This is a common choice for dice rolls and number guessing games.",[14,464,465,466,106],{},"If you want a deeper explanation, see ",[402,467,469],{"href":468},"\u002Fstandard-library\u002Frandom.randint-function-explained","random.randint() explained",[326,471,473],{"id":472},"randomrandrangestart-stop-step",[18,474,475],{},"random.randrange(start, stop[, step])",[14,477,478,479,482],{},"Works like ",[18,480,481],{},"range()",", but returns one random value from that range.",[62,484,486],{"className":64,"code":485,"language":66,"meta":67,"style":67},"import random\n\nprint(random.randrange(0, 10))\nprint(random.randrange(0, 10, 2))\n",[18,487,488,494,498,522],{"__ignoreMap":67},[71,489,490,492],{"class":73,"line":74},[71,491,78],{"class":77},[71,493,82],{"class":81},[71,495,496],{"class":73,"line":85},[71,497,89],{"emptyLinePlaceholder":88},[71,499,500,502,504,506,508,511,513,516,518,520],{"class":73,"line":92},[71,501,96],{"class":95},[71,503,100],{"class":99},[71,505,20],{"class":103},[71,507,106],{"class":99},[71,509,510],{"class":103},"randrange",[71,512,100],{"class":99},[71,514,515],{"class":114},"0",[71,517,118],{"class":99},[71,519,121],{"class":114},[71,521,124],{"class":99},[71,523,524,526,528,530,532,534,536,538,540,542,544,547],{"class":73,"line":127},[71,525,96],{"class":95},[71,527,100],{"class":99},[71,529,20],{"class":103},[71,531,106],{"class":99},[71,533,510],{"class":103},[71,535,100],{"class":99},[71,537,515],{"class":114},[71,539,118],{"class":99},[71,541,121],{"class":114},[71,543,118],{"class":99},[71,545,546],{"class":114}," 2",[71,548,124],{"class":99},[14,550,378],{},[62,552,554],{"className":64,"code":553,"language":66,"meta":67,"style":67},"7\n4\n",[18,555,556,561],{"__ignoreMap":67},[71,557,558],{"class":73,"line":74},[71,559,560],{"class":114},"7\n",[71,562,563],{"class":73,"line":85},[71,564,453],{"class":114},[14,566,567],{},"Important detail:",[26,569,570,582],{},[29,571,572,575,576,578,579],{},[18,573,574],{},"random.randrange(0, 10)"," can return ",[18,577,515],{}," through ",[18,580,581],{},"9",[29,583,584,585,587,588],{},"it does ",[48,586,50],{}," include ",[18,589,590],{},"10",[14,592,593,594,106],{},"This is one of the main differences from ",[18,595,196],{},[326,597,599],{"id":598},"randomchoiceseq",[18,600,601],{},"random.choice(seq)",[14,603,604],{},"Returns one random item from a sequence such as a list, tuple, or string.",[62,606,608],{"className":64,"code":607,"language":66,"meta":67,"style":67},"import random\n\nfruits = [\"apple\", \"banana\", \"cherry\"]\nprint(random.choice(fruits))\n",[18,609,610,616,620,653],{"__ignoreMap":67},[71,611,612,614],{"class":73,"line":74},[71,613,78],{"class":77},[71,615,82],{"class":81},[71,617,618],{"class":73,"line":85},[71,619,89],{"emptyLinePlaceholder":88},[71,621,622,625,627,629,631,633,635,637,639,641,643,645,647,649,651],{"class":73,"line":92},[71,623,624],{"class":81},"fruits ",[71,626,134],{"class":133},[71,628,137],{"class":99},[71,630,141],{"class":140},[71,632,145],{"class":144},[71,634,141],{"class":140},[71,636,118],{"class":99},[71,638,152],{"class":140},[71,640,155],{"class":144},[71,642,141],{"class":140},[71,644,118],{"class":99},[71,646,152],{"class":140},[71,648,164],{"class":144},[71,650,141],{"class":140},[71,652,169],{"class":99},[71,654,655,657,659,661,663,665,667,670],{"class":73,"line":127},[71,656,96],{"class":95},[71,658,100],{"class":99},[71,660,20],{"class":103},[71,662,106],{"class":99},[71,664,183],{"class":103},[71,666,100],{"class":99},[71,668,669],{"class":103},"fruits",[71,671,124],{"class":99},[14,673,378],{},[62,675,677],{"className":64,"code":676,"language":66,"meta":67,"style":67},"banana\n",[18,678,679],{"__ignoreMap":67},[71,680,681],{"class":73,"line":74},[71,682,676],{"class":81},[14,684,685],{},"It also works with strings:",[62,687,689],{"className":64,"code":688,"language":66,"meta":67,"style":67},"import random\n\nprint(random.choice(\"python\"))\n",[18,690,691,697,701],{"__ignoreMap":67},[71,692,693,695],{"class":73,"line":74},[71,694,78],{"class":77},[71,696,82],{"class":81},[71,698,699],{"class":73,"line":85},[71,700,89],{"emptyLinePlaceholder":88},[71,702,703,705,707,709,711,713,715,717,719,721],{"class":73,"line":92},[71,704,96],{"class":95},[71,706,100],{"class":99},[71,708,20],{"class":103},[71,710,106],{"class":99},[71,712,183],{"class":103},[71,714,100],{"class":99},[71,716,141],{"class":140},[71,718,66],{"class":144},[71,720,141],{"class":140},[71,722,124],{"class":99},[14,724,378],{},[62,726,728],{"className":64,"code":727,"language":66,"meta":67,"style":67},"t\n",[18,729,730],{"__ignoreMap":67},[71,731,732],{"class":73,"line":74},[71,733,727],{"class":81},[14,735,736,737,106],{},"For more detail, see ",[402,738,740],{"href":739},"\u002Fstandard-library\u002Frandom.choice-function-explained","random.choice() explained",[326,742,744],{"id":743},"randomchoicesseq-kn",[18,745,746],{},"random.choices(seq, k=n)",[14,748,749,750,106],{},"Returns multiple random items. Values ",[48,751,752],{},"can repeat",[62,754,756],{"className":64,"code":755,"language":66,"meta":67,"style":67},"import random\n\ncolors = [\"red\", \"blue\", \"green\"]\nprint(random.choices(colors, k=5))\n",[18,757,758,764,768,804],{"__ignoreMap":67},[71,759,760,762],{"class":73,"line":74},[71,761,78],{"class":77},[71,763,82],{"class":81},[71,765,766],{"class":73,"line":85},[71,767,89],{"emptyLinePlaceholder":88},[71,769,770,773,775,777,779,782,784,786,788,791,793,795,797,800,802],{"class":73,"line":92},[71,771,772],{"class":81},"colors ",[71,774,134],{"class":133},[71,776,137],{"class":99},[71,778,141],{"class":140},[71,780,781],{"class":144},"red",[71,783,141],{"class":140},[71,785,118],{"class":99},[71,787,152],{"class":140},[71,789,790],{"class":144},"blue",[71,792,141],{"class":140},[71,794,118],{"class":99},[71,796,152],{"class":140},[71,798,799],{"class":144},"green",[71,801,141],{"class":140},[71,803,169],{"class":99},[71,805,806,808,810,812,814,817,819,822,824,828,830,833],{"class":73,"line":127},[71,807,96],{"class":95},[71,809,100],{"class":99},[71,811,20],{"class":103},[71,813,106],{"class":99},[71,815,816],{"class":103},"choices",[71,818,100],{"class":99},[71,820,821],{"class":103},"colors",[71,823,118],{"class":99},[71,825,827],{"class":826},"s99_P"," k",[71,829,134],{"class":133},[71,831,832],{"class":114},"5",[71,834,124],{"class":99},[14,836,378],{},[62,838,840],{"className":64,"code":839,"language":66,"meta":67,"style":67},"['blue', 'red', 'blue', 'green', 'blue']\n",[18,841,842],{"__ignoreMap":67},[71,843,844,847,850,852,854,856,859,861,863,865,867,869,871,873,875,877,879,881,883,885,887],{"class":73,"line":74},[71,845,846],{"class":99},"[",[71,848,849],{"class":140},"'",[71,851,790],{"class":144},[71,853,849],{"class":140},[71,855,118],{"class":99},[71,857,858],{"class":140}," '",[71,860,781],{"class":144},[71,862,849],{"class":140},[71,864,118],{"class":99},[71,866,858],{"class":140},[71,868,790],{"class":144},[71,870,849],{"class":140},[71,872,118],{"class":99},[71,874,858],{"class":140},[71,876,799],{"class":144},[71,878,849],{"class":140},[71,880,118],{"class":99},[71,882,858],{"class":140},[71,884,790],{"class":144},[71,886,849],{"class":140},[71,888,169],{"class":99},[14,890,891],{},"Use this when repeats are allowed.",[326,893,895],{"id":894},"randomsampleseq-kn",[18,896,897],{},"random.sample(seq, k=n)",[14,899,900,901,904],{},"Returns multiple ",[48,902,903],{},"unique"," random items.",[62,906,908],{"className":64,"code":907,"language":66,"meta":67,"style":67},"import random\n\nnumbers = [1, 2, 3, 4, 5]\nprint(random.sample(numbers, k=3))\n",[18,909,910,916,920,952],{"__ignoreMap":67},[71,911,912,914],{"class":73,"line":74},[71,913,78],{"class":77},[71,915,82],{"class":81},[71,917,918],{"class":73,"line":85},[71,919,89],{"emptyLinePlaceholder":88},[71,921,922,925,927,929,931,933,935,937,940,942,945,947,950],{"class":73,"line":92},[71,923,924],{"class":81},"numbers ",[71,926,134],{"class":133},[71,928,137],{"class":99},[71,930,115],{"class":114},[71,932,118],{"class":99},[71,934,546],{"class":114},[71,936,118],{"class":99},[71,938,939],{"class":114}," 3",[71,941,118],{"class":99},[71,943,944],{"class":114}," 4",[71,946,118],{"class":99},[71,948,949],{"class":114}," 5",[71,951,169],{"class":99},[71,953,954,956,958,960,962,965,967,970,972,974,976,979],{"class":73,"line":127},[71,955,96],{"class":95},[71,957,100],{"class":99},[71,959,20],{"class":103},[71,961,106],{"class":99},[71,963,964],{"class":103},"sample",[71,966,100],{"class":99},[71,968,969],{"class":103},"numbers",[71,971,118],{"class":99},[71,973,827],{"class":826},[71,975,134],{"class":133},[71,977,978],{"class":114},"3",[71,980,124],{"class":99},[14,982,378],{},[62,984,986],{"className":64,"code":985,"language":66,"meta":67,"style":67},"[5, 2, 1]\n",[18,987,988],{"__ignoreMap":67},[71,989,990,992,994,996,998,1000,1003],{"class":73,"line":74},[71,991,846],{"class":99},[71,993,832],{"class":114},[71,995,118],{"class":99},[71,997,546],{"class":114},[71,999,118],{"class":99},[71,1001,1002],{"class":114}," 1",[71,1004,169],{"class":99},[14,1006,1007,1008,106],{},"Use this when you want random items with ",[48,1009,1010],{},"no duplicates",[326,1012,1014],{"id":1013},"randomshufflex",[18,1015,1016],{},"random.shuffle(x)",[14,1018,1019,1020,106],{},"Shuffles a list ",[48,1021,1022],{},"in place",[62,1024,1026],{"className":64,"code":1025,"language":66,"meta":67,"style":67},"import random\n\ndata = [1, 2, 3, 4, 5]\nrandom.shuffle(data)\nprint(data)\n",[18,1027,1028,1034,1038,1067,1084],{"__ignoreMap":67},[71,1029,1030,1032],{"class":73,"line":74},[71,1031,78],{"class":77},[71,1033,82],{"class":81},[71,1035,1036],{"class":73,"line":85},[71,1037,89],{"emptyLinePlaceholder":88},[71,1039,1040,1043,1045,1047,1049,1051,1053,1055,1057,1059,1061,1063,1065],{"class":73,"line":92},[71,1041,1042],{"class":81},"data ",[71,1044,134],{"class":133},[71,1046,137],{"class":99},[71,1048,115],{"class":114},[71,1050,118],{"class":99},[71,1052,546],{"class":114},[71,1054,118],{"class":99},[71,1056,939],{"class":114},[71,1058,118],{"class":99},[71,1060,944],{"class":114},[71,1062,118],{"class":99},[71,1064,949],{"class":114},[71,1066,169],{"class":99},[71,1068,1069,1071,1073,1076,1078,1081],{"class":73,"line":127},[71,1070,20],{"class":81},[71,1072,106],{"class":99},[71,1074,1075],{"class":103},"shuffle",[71,1077,100],{"class":99},[71,1079,1080],{"class":103},"data",[71,1082,1083],{"class":99},")\n",[71,1085,1086,1088,1090,1092],{"class":73,"line":172},[71,1087,96],{"class":95},[71,1089,100],{"class":99},[71,1091,1080],{"class":103},[71,1093,1083],{"class":99},[14,1095,378],{},[62,1097,1099],{"className":64,"code":1098,"language":66,"meta":67,"style":67},"[3, 5, 1, 4, 2]\n",[18,1100,1101],{"__ignoreMap":67},[71,1102,1103,1105,1107,1109,1111,1113,1115,1117,1119,1121,1123],{"class":73,"line":74},[71,1104,846],{"class":99},[71,1106,978],{"class":114},[71,1108,118],{"class":99},[71,1110,949],{"class":114},[71,1112,118],{"class":99},[71,1114,1002],{"class":114},[71,1116,118],{"class":99},[71,1118,944],{"class":114},[71,1120,118],{"class":99},[71,1122,546],{"class":114},[71,1124,169],{"class":99},[14,1126,1127,1128,1131],{},"Important: ",[18,1129,1130],{},"shuffle()"," changes the original list. It does not create a new one.",[14,1133,736,1134,106],{},[402,1135,1137],{"href":1136},"\u002Fstandard-library\u002Frandom.shuffle-function-explained","random.shuffle() explained",[57,1139,1141],{"id":1140},"important-beginner-rules","Important beginner rules",[14,1143,1144,1145,1147],{},"Keep these rules in mind when using ",[18,1146,20],{},":",[26,1149,1150,1156,1161,1166,1172],{},[29,1151,1152,1153],{},"Always import the module first with ",[18,1154,1155],{},"import random",[29,1157,193,1158,1160],{},[18,1159,200],{}," only with a non-empty sequence",[29,1162,1163,1165],{},[18,1164,1130],{}," changes the original list",[29,1167,1168,1171],{},[18,1169,1170],{},"sample()"," cannot choose more unique items than the sequence contains",[29,1173,1174,1176],{},[18,1175,196],{}," includes both the start and end values",[14,1178,1179],{},"Here is a simple example that combines several functions:",[62,1181,1183],{"className":64,"code":1182,"language":66,"meta":67,"style":67},"import random\n\nnames = [\"Ana\", \"Ben\", \"Cara\", \"Drew\"]\n\nprint(\"Random name:\", random.choice(names))\nprint(\"Random number:\", random.randint(1, 10))\nprint(\"Two unique names:\", random.sample(names, k=2))\n\nrandom.shuffle(names)\nprint(\"Shuffled list:\", names)\n",[18,1184,1185,1191,1195,1240,1244,1273,1305,1342,1347,1362],{"__ignoreMap":67},[71,1186,1187,1189],{"class":73,"line":74},[71,1188,78],{"class":77},[71,1190,82],{"class":81},[71,1192,1193],{"class":73,"line":85},[71,1194,89],{"emptyLinePlaceholder":88},[71,1196,1197,1200,1202,1204,1206,1209,1211,1213,1215,1218,1220,1222,1224,1227,1229,1231,1233,1236,1238],{"class":73,"line":92},[71,1198,1199],{"class":81},"names ",[71,1201,134],{"class":133},[71,1203,137],{"class":99},[71,1205,141],{"class":140},[71,1207,1208],{"class":144},"Ana",[71,1210,141],{"class":140},[71,1212,118],{"class":99},[71,1214,152],{"class":140},[71,1216,1217],{"class":144},"Ben",[71,1219,141],{"class":140},[71,1221,118],{"class":99},[71,1223,152],{"class":140},[71,1225,1226],{"class":144},"Cara",[71,1228,141],{"class":140},[71,1230,118],{"class":99},[71,1232,152],{"class":140},[71,1234,1235],{"class":144},"Drew",[71,1237,141],{"class":140},[71,1239,169],{"class":99},[71,1241,1242],{"class":73,"line":127},[71,1243,89],{"emptyLinePlaceholder":88},[71,1245,1246,1248,1250,1252,1255,1257,1259,1262,1264,1266,1268,1271],{"class":73,"line":172},[71,1247,96],{"class":95},[71,1249,100],{"class":99},[71,1251,141],{"class":140},[71,1253,1254],{"class":144},"Random name:",[71,1256,141],{"class":140},[71,1258,118],{"class":99},[71,1260,1261],{"class":103}," random",[71,1263,106],{"class":99},[71,1265,183],{"class":103},[71,1267,100],{"class":99},[71,1269,1270],{"class":103},"names",[71,1272,124],{"class":99},[71,1274,1276,1278,1280,1282,1285,1287,1289,1291,1293,1295,1297,1299,1301,1303],{"class":73,"line":1275},6,[71,1277,96],{"class":95},[71,1279,100],{"class":99},[71,1281,141],{"class":140},[71,1283,1284],{"class":144},"Random number:",[71,1286,141],{"class":140},[71,1288,118],{"class":99},[71,1290,1261],{"class":103},[71,1292,106],{"class":99},[71,1294,109],{"class":103},[71,1296,100],{"class":99},[71,1298,115],{"class":114},[71,1300,118],{"class":99},[71,1302,121],{"class":114},[71,1304,124],{"class":99},[71,1306,1308,1310,1312,1314,1317,1319,1321,1323,1325,1327,1329,1331,1333,1335,1337,1340],{"class":73,"line":1307},7,[71,1309,96],{"class":95},[71,1311,100],{"class":99},[71,1313,141],{"class":140},[71,1315,1316],{"class":144},"Two unique names:",[71,1318,141],{"class":140},[71,1320,118],{"class":99},[71,1322,1261],{"class":103},[71,1324,106],{"class":99},[71,1326,964],{"class":103},[71,1328,100],{"class":99},[71,1330,1270],{"class":103},[71,1332,118],{"class":99},[71,1334,827],{"class":826},[71,1336,134],{"class":133},[71,1338,1339],{"class":114},"2",[71,1341,124],{"class":99},[71,1343,1345],{"class":73,"line":1344},8,[71,1346,89],{"emptyLinePlaceholder":88},[71,1348,1350,1352,1354,1356,1358,1360],{"class":73,"line":1349},9,[71,1351,20],{"class":81},[71,1353,106],{"class":99},[71,1355,1075],{"class":103},[71,1357,100],{"class":99},[71,1359,1270],{"class":103},[71,1361,1083],{"class":99},[71,1363,1365,1367,1369,1371,1374,1376,1378,1381],{"class":73,"line":1364},10,[71,1366,96],{"class":95},[71,1368,100],{"class":99},[71,1370,141],{"class":140},[71,1372,1373],{"class":144},"Shuffled list:",[71,1375,141],{"class":140},[71,1377,118],{"class":99},[71,1379,1380],{"class":103}," names",[71,1382,1083],{"class":99},[57,1384,1386],{"id":1385},"pseudo-random-vs-truly-random","Pseudo-random vs truly random",[14,1388,16,1389,1391,1392,1395],{},[18,1390,20],{}," module produces values that ",[48,1393,1394],{},"look random",", but they come from a mathematical process.",[14,1397,1398],{},"For most beginner programs, that is completely fine.",[14,1400,193,1401,240],{},[18,1402,20],{},[26,1404,1405,1408,1411,1414],{},[29,1406,1407],{},"games",[29,1409,1410],{},"practice projects",[29,1412,1413],{},"simulations",[29,1415,1416],{},"random test data",[14,1418,1419,1420,1422],{},"Use the ",[18,1421,54],{}," module instead for:",[26,1424,1425,1427,1430,1433],{},[29,1426,265],{},[29,1428,1429],{},"reset links",[29,1431,1432],{},"access tokens",[29,1434,1435],{},"security codes",[57,1437,1439],{"id":1438},"common-problems-and-confusion","Common problems and confusion",[14,1441,1442,1443,106],{},"Here are some common mistakes beginners make with ",[18,1444,20],{},[326,1446,1448,1449],{"id":1447},"forgetting-to-import-random","Forgetting to import ",[18,1450,20],{},[14,1452,1453,1454,1457,1458,106],{},"If you use ",[18,1455,1456],{},"random.randint()"," without importing the module first, you will get a ",[18,1459,1460],{},"NameError",[62,1462,1464],{"className":64,"code":1463,"language":66,"meta":67,"style":67},"print(random.randint(1, 10))\n",[18,1465,1466],{"__ignoreMap":67},[71,1467,1468,1470,1472,1474,1476,1478,1480,1482,1484,1486],{"class":73,"line":74},[71,1469,96],{"class":95},[71,1471,100],{"class":99},[71,1473,20],{"class":103},[71,1475,106],{"class":99},[71,1477,109],{"class":103},[71,1479,100],{"class":99},[71,1481,115],{"class":114},[71,1483,118],{"class":99},[71,1485,121],{"class":114},[71,1487,124],{"class":99},[14,1489,1490],{},"Fix it by adding:",[62,1492,1494],{"className":64,"code":1493,"language":66,"meta":67,"style":67},"import random\n",[18,1495,1496],{"__ignoreMap":67},[71,1497,1498,1500],{"class":73,"line":74},[71,1499,78],{"class":77},[71,1501,82],{"class":81},[14,1503,1504,1505,106],{},"If needed, read ",[402,1506,1508],{"href":1507},"\u002Ferrors\u002Fnameerror-name-is-not-defined-fix\u002F","how to fix NameError: name is not defined",[326,1510,1512,1513,1515],{"id":1511},"using-choice-with-an-empty-list","Using ",[18,1514,200],{}," with an empty list",[14,1517,1518],{},"This causes an error because there is nothing to choose.",[62,1520,1522],{"className":64,"code":1521,"language":66,"meta":67,"style":67},"import random\n\nitems = []\nprint(random.choice(items))\n",[18,1523,1524,1530,1534,1543],{"__ignoreMap":67},[71,1525,1526,1528],{"class":73,"line":74},[71,1527,78],{"class":77},[71,1529,82],{"class":81},[71,1531,1532],{"class":73,"line":85},[71,1533,89],{"emptyLinePlaceholder":88},[71,1535,1536,1538,1540],{"class":73,"line":92},[71,1537,130],{"class":81},[71,1539,134],{"class":133},[71,1541,1542],{"class":99}," []\n",[71,1544,1545,1547,1549,1551,1553,1555,1557,1559],{"class":73,"line":127},[71,1546,96],{"class":95},[71,1548,100],{"class":99},[71,1550,20],{"class":103},[71,1552,106],{"class":99},[71,1554,183],{"class":103},[71,1556,100],{"class":99},[71,1558,188],{"class":103},[71,1560,124],{"class":99},[14,1562,1563,1564,106],{},"Make sure the sequence is not empty before calling ",[18,1565,200],{},[62,1567,1569],{"className":64,"code":1568,"language":66,"meta":67,"style":67},"import random\n\nitems = [\"apple\", \"banana\"]\n\nif items:\n    print(random.choice(items))\n",[18,1570,1571,1577,1581,1605,1609,1620],{"__ignoreMap":67},[71,1572,1573,1575],{"class":73,"line":74},[71,1574,78],{"class":77},[71,1576,82],{"class":81},[71,1578,1579],{"class":73,"line":85},[71,1580,89],{"emptyLinePlaceholder":88},[71,1582,1583,1585,1587,1589,1591,1593,1595,1597,1599,1601,1603],{"class":73,"line":92},[71,1584,130],{"class":81},[71,1586,134],{"class":133},[71,1588,137],{"class":99},[71,1590,141],{"class":140},[71,1592,145],{"class":144},[71,1594,141],{"class":140},[71,1596,118],{"class":99},[71,1598,152],{"class":140},[71,1600,155],{"class":144},[71,1602,141],{"class":140},[71,1604,169],{"class":99},[71,1606,1607],{"class":73,"line":127},[71,1608,89],{"emptyLinePlaceholder":88},[71,1610,1611,1614,1617],{"class":73,"line":172},[71,1612,1613],{"class":77},"if",[71,1615,1616],{"class":81}," items",[71,1618,1619],{"class":99},":\n",[71,1621,1622,1625,1627,1629,1631,1633,1635,1637],{"class":73,"line":1275},[71,1623,1624],{"class":95},"    print",[71,1626,100],{"class":99},[71,1628,20],{"class":103},[71,1630,106],{"class":99},[71,1632,183],{"class":103},[71,1634,100],{"class":99},[71,1636,188],{"class":103},[71,1638,124],{"class":99},[326,1640,1642,1643,1645],{"id":1641},"expecting-shuffle-to-return-a-new-list","Expecting ",[18,1644,1130],{}," to return a new list",[14,1647,1648],{},"This is a very common mistake:",[62,1650,1652],{"className":64,"code":1651,"language":66,"meta":67,"style":67},"import random\n\nmy_list = [1, 2, 3]\nresult = random.shuffle(my_list)\nprint(result)\n",[18,1653,1654,1660,1664,1685,1705],{"__ignoreMap":67},[71,1655,1656,1658],{"class":73,"line":74},[71,1657,78],{"class":77},[71,1659,82],{"class":81},[71,1661,1662],{"class":73,"line":85},[71,1663,89],{"emptyLinePlaceholder":88},[71,1665,1666,1669,1671,1673,1675,1677,1679,1681,1683],{"class":73,"line":92},[71,1667,1668],{"class":81},"my_list ",[71,1670,134],{"class":133},[71,1672,137],{"class":99},[71,1674,115],{"class":114},[71,1676,118],{"class":99},[71,1678,546],{"class":114},[71,1680,118],{"class":99},[71,1682,939],{"class":114},[71,1684,169],{"class":99},[71,1686,1687,1690,1692,1694,1696,1698,1700,1703],{"class":73,"line":127},[71,1688,1689],{"class":81},"result ",[71,1691,134],{"class":133},[71,1693,1261],{"class":81},[71,1695,106],{"class":99},[71,1697,1075],{"class":103},[71,1699,100],{"class":99},[71,1701,1702],{"class":103},"my_list",[71,1704,1083],{"class":99},[71,1706,1707,1709,1711,1714],{"class":73,"line":172},[71,1708,96],{"class":95},[71,1710,100],{"class":99},[71,1712,1713],{"class":103},"result",[71,1715,1083],{"class":99},[14,1717,1718],{},"Output:",[62,1720,1722],{"className":64,"code":1721,"language":66,"meta":67,"style":67},"None\n",[18,1723,1724],{"__ignoreMap":67},[71,1725,1726],{"class":73,"line":74},[71,1727,1721],{"class":1728},"s39Yj",[14,1730,1731,1732,1734],{},"Why? Because ",[18,1733,1130],{}," changes the original list directly.",[14,1736,1737],{},"Correct version:",[62,1739,1741],{"className":64,"code":1740,"language":66,"meta":67,"style":67},"import random\n\nmy_list = [1, 2, 3]\nrandom.shuffle(my_list)\nprint(my_list)\n",[18,1742,1743,1749,1753,1773,1787],{"__ignoreMap":67},[71,1744,1745,1747],{"class":73,"line":74},[71,1746,78],{"class":77},[71,1748,82],{"class":81},[71,1750,1751],{"class":73,"line":85},[71,1752,89],{"emptyLinePlaceholder":88},[71,1754,1755,1757,1759,1761,1763,1765,1767,1769,1771],{"class":73,"line":92},[71,1756,1668],{"class":81},[71,1758,134],{"class":133},[71,1760,137],{"class":99},[71,1762,115],{"class":114},[71,1764,118],{"class":99},[71,1766,546],{"class":114},[71,1768,118],{"class":99},[71,1770,939],{"class":114},[71,1772,169],{"class":99},[71,1774,1775,1777,1779,1781,1783,1785],{"class":73,"line":127},[71,1776,20],{"class":81},[71,1778,106],{"class":99},[71,1780,1075],{"class":103},[71,1782,100],{"class":99},[71,1784,1702],{"class":103},[71,1786,1083],{"class":99},[71,1788,1789,1791,1793,1795],{"class":73,"line":172},[71,1790,96],{"class":95},[71,1792,100],{"class":99},[71,1794,1702],{"class":103},[71,1796,1083],{"class":99},[326,1798,1800,1801,1803,1804],{"id":1799},"mixing-up-randint-and-randrange","Mixing up ",[18,1802,196],{}," and ",[18,1805,1806],{},"randrange()",[14,1808,1809],{},"These two functions are similar, but they do not behave exactly the same.",[62,1811,1813],{"className":64,"code":1812,"language":66,"meta":67,"style":67},"import random\n\nprint(random.randint(1, 10))   # can return 10\nprint(random.randrange(1, 10)) # cannot return 10\n",[18,1814,1815,1821,1825,1852],{"__ignoreMap":67},[71,1816,1817,1819],{"class":73,"line":74},[71,1818,78],{"class":77},[71,1820,82],{"class":81},[71,1822,1823],{"class":73,"line":85},[71,1824,89],{"emptyLinePlaceholder":88},[71,1826,1827,1829,1831,1833,1835,1837,1839,1841,1843,1845,1848],{"class":73,"line":92},[71,1828,96],{"class":95},[71,1830,100],{"class":99},[71,1832,20],{"class":103},[71,1834,106],{"class":99},[71,1836,109],{"class":103},[71,1838,100],{"class":99},[71,1840,115],{"class":114},[71,1842,118],{"class":99},[71,1844,121],{"class":114},[71,1846,1847],{"class":99},"))",[71,1849,1851],{"class":1850},"sutJx","   # can return 10\n",[71,1853,1854,1856,1858,1860,1862,1864,1866,1868,1870,1872,1874],{"class":73,"line":127},[71,1855,96],{"class":95},[71,1857,100],{"class":99},[71,1859,20],{"class":103},[71,1861,106],{"class":99},[71,1863,510],{"class":103},[71,1865,100],{"class":99},[71,1867,115],{"class":114},[71,1869,118],{"class":99},[71,1871,121],{"class":114},[71,1873,1847],{"class":99},[71,1875,1876],{"class":1850}," # cannot return 10\n",[14,1878,1879],{},"This difference can cause off-by-one mistakes.",[57,1881,1883],{"id":1882},"common-mistakes","Common mistakes",[14,1885,1886],{},"These are some beginner mistakes to watch for:",[26,1888,1889,1894,1904,1911,1916],{},[29,1890,1512,1891,1515],{},[18,1892,1893],{},"random.choice()",[29,1895,1896,1897,1900,1901],{},"Writing ",[18,1898,1899],{},"random(1, 10)"," instead of ",[18,1902,1903],{},"random.randint(1, 10)",[29,1905,1906,1907,1910],{},"Assigning ",[18,1908,1909],{},"result = random.shuffle(my_list)"," and expecting a shuffled list back",[29,1912,1512,1913,1915],{},[18,1914,20],{}," for passwords or secure tokens",[29,1917,1918,1919,1921],{},"Forgetting that ",[18,1920,196],{}," includes the end value",[14,1923,1924,1925,106],{},"If you work with lists a lot, it helps to understand how they behave first. See ",[402,1926,1928],{"href":1927},"\u002Flearn\u002Fpython-lists-explained-beginner-guide\u002F","Python lists explained for beginners",[57,1930,1932],{"id":1931},"useful-test-commands","Useful test commands",[14,1934,1935],{},"You can quickly test the module from the command line:",[62,1937,1941],{"className":1938,"code":1939,"language":1940,"meta":67,"style":67},"language-bash shiki shiki-themes material-theme-lighter github-light github-dark","python --version\npython -c \"import random; print(random.randint(1, 10))\"\npython -c \"import random; data=[1,2,3]; random.shuffle(data); print(data)\"\npython -c \"import random; print(random.choice(['a','b','c']))\"\n","bash",[18,1942,1943,1952,1967,1980],{"__ignoreMap":67},[71,1944,1945,1948],{"class":73,"line":74},[71,1946,66],{"class":1947},"sbgvK",[71,1949,1951],{"class":1950},"stzsN"," --version\n",[71,1953,1954,1956,1959,1961,1964],{"class":73,"line":85},[71,1955,66],{"class":1947},[71,1957,1958],{"class":1950}," -c",[71,1960,152],{"class":140},[71,1962,1963],{"class":144},"import random; print(random.randint(1, 10))",[71,1965,1966],{"class":140},"\"\n",[71,1968,1969,1971,1973,1975,1978],{"class":73,"line":92},[71,1970,66],{"class":1947},[71,1972,1958],{"class":1950},[71,1974,152],{"class":140},[71,1976,1977],{"class":144},"import random; data=[1,2,3]; random.shuffle(data); print(data)",[71,1979,1966],{"class":140},[71,1981,1982,1984,1986,1988,1991],{"class":73,"line":127},[71,1983,66],{"class":1947},[71,1985,1958],{"class":1950},[71,1987,152],{"class":140},[71,1989,1990],{"class":144},"import random; print(random.choice(['a','b','c']))",[71,1992,1966],{"class":140},[57,1994,1996],{"id":1995},"faq","FAQ",[326,1998,2000],{"id":1999},"do-i-need-to-install-the-random-module","Do I need to install the random module?",[14,2002,2003,2004,2006],{},"No. ",[18,2005,20],{}," is part of Python's standard library.",[326,2008,2010,2011,1803,2013,2015],{"id":2009},"what-is-the-difference-between-randint-and-randrange","What is the difference between ",[18,2012,196],{},[18,2014,1806],{},"?",[14,2017,2018,2021],{},[18,2019,2020],{},"randint(a, b)"," includes both ends.",[14,2023,2024,2026,2027,2029],{},[18,2025,1806],{}," works more like ",[18,2028,481],{}," and usually excludes the stop value.",[326,2031,2033,2034,2036,2037,2015],{"id":2032},"why-does-shuffle-return-none","Why does ",[18,2035,1130],{}," return ",[18,2038,2039],{},"None",[14,2041,2042],{},"Because it changes the original list directly instead of creating a new one.",[326,2044,2046,2047,2049],{"id":2045},"can-randomchoice-work-with-strings","Can ",[18,2048,1893],{}," work with strings?",[14,2051,2052,2053,2055],{},"Yes. A string is a sequence, so ",[18,2054,200],{}," can return one random character.",[326,2057,2059,2060,2062],{"id":2058},"should-i-use-random-for-passwords","Should I use ",[18,2061,20],{}," for passwords?",[14,2064,2065,2066,2068],{},"No. Use the ",[18,2067,54],{}," module for security-related values.",[57,2070,2072],{"id":2071},"see-also","See also",[26,2074,2075,2079,2083,2087,2091,2096],{},[29,2076,2077],{},[402,2078,469],{"href":468},[29,2080,2081],{},[402,2082,740],{"href":739},[29,2084,2085],{},[402,2086,1137],{"href":1136},[29,2088,2089],{},[402,2090,1928],{"href":1927},[29,2092,2093],{},[402,2094,2095],{"href":1507},"How to fix NameError: name is not defined",[29,2097,2098],{},[402,2099,2101],{"href":2100},"\u002Ferrors\u002Findexerror-list-index-out-of-range-fix-explained","How to fix IndexError: list index out of range",[14,2103,2104,2105,2107,2108,2110],{},"Next, read a focused function page like ",[18,2106,1456],{}," or ",[18,2109,1893],{},", then try a small beginner project such as a number guessing game.",[2112,2113,2114],"style",{},"html pre.shiki code .sVHd0, html code.shiki .sVHd0{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#D73A49;--shiki-default-font-style:inherit;--shiki-dark:#F97583;--shiki-dark-font-style:inherit}html pre.shiki code .su5hD, html code.shiki .su5hD{--shiki-light:#90A4AE;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sptTA, html code.shiki .sptTA{--shiki-light:#6182B8;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sP7_E, html code.shiki .sP7_E{--shiki-light:#39ADB5;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .slqww, html code.shiki .slqww{--shiki-light:#6182B8;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .srdBf, html code.shiki .srdBf{--shiki-light:#F76D47;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .smGrS, html code.shiki .smGrS{--shiki-light:#39ADB5;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sjJ54, html code.shiki .sjJ54{--shiki-light:#39ADB5;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .s_sjI, html code.shiki .s_sjI{--shiki-light:#91B859;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .s99_P, html code.shiki .s99_P{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#E36209;--shiki-default-font-style:inherit;--shiki-dark:#FFAB70;--shiki-dark-font-style:inherit}html pre.shiki code .s39Yj, html code.shiki .s39Yj{--shiki-light:#39ADB5;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sutJx, html code.shiki .sutJx{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#6A737D;--shiki-default-font-style:inherit;--shiki-dark:#6A737D;--shiki-dark-font-style:inherit}html pre.shiki code .sbgvK, html code.shiki .sbgvK{--shiki-light:#E2931D;--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .stzsN, html code.shiki .stzsN{--shiki-light:#91B859;--shiki-default:#005CC5;--shiki-dark:#79B8FF}",{"title":67,"searchDepth":85,"depth":85,"links":2116},[2117,2118,2119,2120,2129,2130,2131,2141,2142,2143,2154],{"id":59,"depth":85,"text":60},{"id":204,"depth":85,"text":205},{"id":274,"depth":85,"text":275},{"id":317,"depth":85,"text":318,"children":2121},[2122,2123,2124,2125,2126,2127,2128],{"id":328,"depth":92,"text":331},{"id":393,"depth":92,"text":396},{"id":472,"depth":92,"text":475},{"id":598,"depth":92,"text":601},{"id":743,"depth":92,"text":746},{"id":894,"depth":92,"text":897},{"id":1013,"depth":92,"text":1016},{"id":1140,"depth":85,"text":1141},{"id":1385,"depth":85,"text":1386},{"id":1438,"depth":85,"text":1439,"children":2132},[2133,2135,2137,2139],{"id":1447,"depth":92,"text":2134},"Forgetting to import random",{"id":1511,"depth":92,"text":2136},"Using choice() with an empty list",{"id":1641,"depth":92,"text":2138},"Expecting shuffle() to return a new list",{"id":1799,"depth":92,"text":2140},"Mixing up randint() and randrange()",{"id":1882,"depth":85,"text":1883},{"id":1931,"depth":85,"text":1932},{"id":1995,"depth":85,"text":1996,"children":2144},[2145,2146,2148,2150,2152],{"id":1999,"depth":92,"text":2000},{"id":2009,"depth":92,"text":2147},"What is the difference between randint() and randrange()?",{"id":2032,"depth":92,"text":2149},"Why does shuffle() return None?",{"id":2045,"depth":92,"text":2151},"Can random.choice() work with strings?",{"id":2058,"depth":92,"text":2153},"Should I use random for passwords?",{"id":2071,"depth":85,"text":2072},"Master python random module overview in our comprehensive Python beginner guide.","md",{},"\u002Fstandard-library\u002Fpython-random-module-overview",{"title":5,"description":2155},"standard-library\u002Fpython-random-module-overview","fgpugUWJ2LNurBHjQsthmJ4dN13MBowSf7KGYaNXsDE",1777585471129]