Jupyter 版本的用 Python 实现随机数

也可以点击 这里 获取相关文件呀

Randomness and Reproducibility

  • 随机性及其在Python中的应用
  • 使用Python seeds进行重复分析
  • 从概率分布中生成随机变量
  • 从人群中随机抽样

什么是随机性?

  • 如果有完全的随机性,我们对均值、比例和总和的估计都是无偏的,这也就意味着估计值与群体值的平均值相等
  • 在Python中,把随机性称为随机生成数据、字符串或者一般的数字的能力
  • 在分析时,考虑可重复性是非常重要的
  • 如果正在创建随机数据,如何才能实现可重复性分析呢?
  • 通过伪随机数生成器来实现,也就是所谓的 seed,然后使用算法在此基础上生成一个伪随机序列
  • 也就是可以在 Python 中复制随机数生成器的输出,只需要知道使用的是哪个 seed 即可
  • 可以使用 random 函数展示

设置 seed 、生成随机数

In [1]:
import random
In [2]:
random.seed(1234)
random.random()
Out[2]:
0.9664535356921388
In [3]:
random.seed(1234)
random.random()
Out[3]:
0.9664535356921388

实数分布的随机数

  • Uniform
In [4]:
random.uniform(25, 50)
unifNumbers = [random.uniform(0, 1) for _ in range(1000)]
In [5]:
unifNumbers
Out[5]:
[0.007491470058587191,
 0.9109759624491242,
 0.939268997363764,
 0.5822275730589491,
 0.6715634814879851,
 0.08393822683708396,
 0.7664809327917963,
 0.23680977536311776,
 0.030814021726609964,
 0.7887727172362835,
 0.3460889655971231,
 0.6232814750391685,
 0.6158156951036152,
 0.14855463870828756,
 0.18309064740993164,
 0.11441296968868764,
 0.014618780486909122,
 0.48675154060475834,
 0.9649015609162157,
 0.06456228097718608,
 0.5410881855511303,
 0.46589855900830957,
 0.6014634495610515,
 0.08892882999066232,
 0.5790026861873665,
 0.26958550381944824,
 0.5564325605562156,
 0.6446342341782827,
 0.48103637136651844,
 0.35523914744298335,
 0.249152121361209,
 0.9335154980423467,
 0.45338801947649354,
 0.5301612069115903,
 0.019299566309716853,
 0.5081019257797922,
 0.005780237417743139,
 0.14376842759559538,
 0.47282692534740633,
 0.3773474407725964,
 0.05417519864614284,
 0.5875285081310694,
 0.1640032237419612,
 0.5573302374414681,
 0.1442457216019083,
 0.9373070846962247,
 0.7709799715197749,
 0.9569331223494054,
 0.14122776441649953,
 0.3053927082876986,
 0.03958962422796164,
 0.27678369479169207,
 0.8065125051156038,
 0.177343035278254,
 0.15457051471078964,
 0.9547186557023949,
 0.154551400089043,
 0.8338892941512318,
 0.04106280627180747,
 0.38618352833582825,
 0.3495923019636925,
 0.3417077927504538,
 0.8164630567142304,
 0.47593490813172823,
 0.7828902895224036,
 0.4708401253088451,
 0.8173440068581418,
 0.8815675986556064,
 0.43959639767963965,
 0.781063597792481,
 0.8147411602576974,
 0.29567891564250737,
 0.12387667430690597,
 0.18562186074498854,
 0.4360597935994146,
 0.11946740701121195,
 0.5297991417578831,
 0.8294211614174424,
 0.48520115298643485,
 0.817734001701804,
 0.6563916225394183,
 0.6410430311516905,
 0.3453489252042602,
 0.7026589490483248,
 0.8099405837312028,
 0.15716958478401755,
 0.9079906191155508,
 0.26933036723681814,
 0.15484649574701626,
 0.8404791651944925,
 0.7201279798410062,
 0.7935623957737522,
 0.4466706642559476,
 0.07077388523885675,
 0.3952430502634495,
 0.04773529540398547,
 0.28613350393922754,
 0.037994595016476396,
 0.5067148419441442,
 0.08766779894229271,
 0.9328256468398046,
 0.6993872895717961,
 0.31698602665681064,
 0.9450510700109166,
 0.06622760433688513,
 0.2574288908876978,
 0.07299964643145462,
 0.4263042580299481,
 0.2018967725432862,
 0.39664663519413834,
 0.7048599115494352,
 0.8873533417252499,
 0.5005177947605222,
 0.8185315489586601,
 0.3612545127497995,
 0.8586861730000401,
 0.5150341755872584,
 0.7024154768971624,
 0.1746899184029187,
 0.5845118105654407,
 0.3017770577990323,
 0.8128513943589164,
 0.534340747841153,
 0.4995873041932324,
 0.7733252044833073,
 0.5490306725534498,
 0.3337580124939149,
 0.1309328604345955,
 0.6245059904834612,
 0.9253462191293278,
 0.8423388566528607,
 0.06974978531747122,
 0.3252852050291277,
 0.0017063741999860937,
 0.674697198426907,
 0.6382801166744566,
 0.7579087748535257,
 0.14827392932422656,
 0.2170336920016357,
 0.43277237855971706,
 0.7367248559326753,
 0.2071190027274683,
 0.822836925645994,
 0.38120108795455365,
 0.874285779261748,
 0.960024664402363,
 0.5374877201903263,
 0.9210673593322503,
 0.4220368662398568,
 0.6852700902353918,
 0.8469088461355628,
 0.8387677858221511,
 0.09286882552760667,
 0.2603157630415286,
 0.41025802046110393,
 0.8578243595729985,
 0.2767425293162503,
 0.11373891459151042,
 0.3753484507964998,
 0.21388582361821773,
 0.7162366348291398,
 0.5875095158691588,
 0.052498954158468725,
 0.8774303781577201,
 0.44055508995426507,
 0.7768870405145091,
 0.16532070473240057,
 0.3079171627942351,
 0.07332629323159812,
 0.3949907220782418,
 0.42891036601263643,
 0.6827962907228684,
 0.4795878543375367,
 0.40051186552948925,
 0.4779619809775836,
 0.2812604054175517,
 0.36952543746848865,
 0.6004937465971849,
 0.20606798059479603,
 0.5188643261507528,
 0.929672685027304,
 0.45741745683388324,
 0.6683105116667378,
 0.659843191715288,
 0.8013451680214587,
 0.72555037936488,
 0.6607070326757426,
 0.10371082296156531,
 0.3666337502674558,
 0.7940603902624188,
 0.06519273606004916,
 0.140017657639388,
 0.9053601689290057,
 0.5880174661560316,
 0.9801687624222534,
 0.7535802629064867,
 0.9956779501561271,
 0.2986194989199198,
 0.6860565139581868,
 0.33058674307802494,
 0.9459701027837982,
 0.29378132941223756,
 0.19456632814676655,
 0.8142843600330181,
 0.27903465980652375,
 0.5340336612879176,
 0.6022037133872586,
 0.3396342434754338,
 0.33423486287865234,
 0.32106118245445525,
 0.26750379864093876,
 0.7596723476594016,
 0.5892297370920557,
 0.5482450583548587,
 0.8241385165248288,
 0.2571506080916056,
 0.13708330594430362,
 0.028379070718151822,
 0.037353952710616034,
 0.9906762245601041,
 0.9738146901779593,
 0.666599759122798,
 0.9906604238823697,
 0.5156525027411268,
 0.43455539575769053,
 0.5152842321063046,
 0.0689968455140697,
 0.7595807906796767,
 0.3051615227865051,
 0.6980804464635962,
 0.9095026968405713,
 0.2195990931074855,
 0.5043762779449856,
 0.6531418033725553,
 0.8109583259981676,
 0.6827514215189925,
 0.3310913731348415,
 0.5641798319638229,
 0.1625342926232617,
 0.4994160285960556,
 0.9400480737966925,
 0.9501826986053399,
 0.13993868140764443,
 0.5323137836354301,
 0.6198618119078443,
 0.14553190418628326,
 0.9489909622021919,
 0.24328573561205935,
 0.1642501049788817,
 0.5064316299143288,
 0.5050036064635829,
 0.7734483733263157,
 0.8531773152859777,
 0.326503166026786,
 0.7082273066030744,
 0.5617224169237225,
 0.5350812271995034,
 0.5991991597730171,
 0.44633775979940926,
 0.3717037295452331,
 0.9297231835805264,
 0.7628990548888642,
 0.6758695200711056,
 0.8863110992657115,
 0.604042251497186,
 0.07090205933271287,
 0.2279230104629325,
 0.8030202850564597,
 0.34618632450534537,
 0.939619843075126,
 0.6890522969448506,
 0.379786749108011,
 0.49278592301316826,
 0.05244756512223936,
 0.4480756432264197,
 0.08017791679759956,
 0.2931640477955114,
 0.9292915116273228,
 0.14789399866873065,
 0.6769173499576406,
 0.6507889124902234,
 0.6930677293557751,
 0.7944700794652206,
 0.864256141615212,
 0.35660869323785926,
 0.37141155760736033,
 0.17404943015176322,
 0.6394244880811022,
 0.2122707201192704,
 0.19644951697371693,
 0.9900923118379258,
 0.6204216744570211,
 0.7306470434476072,
 0.5018555817777155,
 0.1325004225542018,
 0.9101820979619671,
 0.6512464042247909,
 0.04950931622445931,
 0.913988170026806,
 0.4680477258678539,
 0.5977597365455833,
 0.37179231113498634,
 0.3966542214766213,
 0.7784075093855664,
 0.23417011860959402,
 0.008745110774384779,
 0.3127493603753806,
 0.9853725974708718,
 0.12047353047299003,
 0.5999055805460092,
 0.8650770054650282,
 0.5339886886707598,
 0.59356522835349,
 0.5371963544480434,
 0.3222368157872887,
 0.3628551724423974,
 0.9266069700784881,
 0.7121430687224548,
 0.6426836041831554,
 0.4568679183105764,
 0.9109721345395123,
 0.876836046600565,
 0.9671488849270804,
 0.5435582451199706,
 0.40860992848148847,
 0.19172149482171597,
 0.27340328569685535,
 0.8677021617214062,
 0.1742466192980301,
 0.945959312779991,
 0.5863581136876328,
 0.8470586345300946,
 0.5301209202867813,
 0.7547609403637685,
 0.587207373090883,
 0.8280736094727759,
 0.5143342721855443,
 0.7242078984559296,
 0.8035059849621691,
 0.37302954210508965,
 0.10258382345376171,
 0.6750024820050281,
 0.8502792447919707,
 0.8340532524888558,
 0.12704253275763078,
 0.7844155093234709,
 0.4881053723153571,
 0.5463551100918587,
 0.13183867043041952,
 0.7696514968268633,
 0.23897272342349563,
 0.6985023623024105,
 0.3353079288615486,
 0.956611896258508,
 0.7115023547574234,
 0.3549770892074753,
 0.5480485771139187,
 0.18834670339173143,
 0.47292446848559455,
 0.9311340277999263,
 0.9290215705758647,
 0.3195430483356907,
 0.4415809431545962,
 0.5248704933218673,
 0.5391696081492233,
 0.9895920415461077,
 0.08587229308528133,
 0.19746010136460634,
 0.6077045716141891,
 0.33589283505568746,
 0.3777553608379741,
 0.6949131483398894,
 0.199594954137308,
 0.029381932006439127,
 0.9708305795619522,
 0.31603671313914794,
 0.09975037012430676,
 0.05568992202538603,
 0.6796457861390139,
 0.4239935451983131,
 0.3399557345205959,
 0.979684022012074,
 0.929596285773352,
 0.7147713793571463,
 0.9025336405654067,
 0.16626346391252145,
 0.9724287196588562,
 0.008851776190800242,
 0.5965995907361062,
 0.9214747345723373,
 0.9098749520625241,
 0.7038227268801873,
 0.9260150854041772,
 0.6093798894348853,
 0.1560840371327744,
 0.9207622323786137,
 0.1942979142821678,
 0.45294828419985445,
 0.4450296492688718,
 0.5018423859329986,
 0.33639666082787933,
 0.2687583477045947,
 0.8889116677274447,
 0.39177734598264335,
 0.6855585096362641,
 0.4935494163270612,
 0.24769106382856143,
 0.2862031620577271,
 0.9701953095489171,
 0.9039031148764954,
 0.1576296317163257,
 0.2325579566978364,
 0.9589520435420135,
 0.9214968158467663,
 0.35384767970573383,
 0.5438500285615716,
 0.43009759424612415,
 0.4442691059723931,
 0.5498786449757813,
 0.7799050366072715,
 0.7182024634234199,
 0.7174416040113839,
 0.07081493598518485,
 0.24439959843730552,
 0.6464594779992874,
 0.7137197471065294,
 0.4854514478125008,
 0.7795098705788651,
 0.9566563758067148,
 0.6924931504035324,
 0.8323985450949843,
 0.32727485123976296,
 0.8174644598316574,
 0.5183725316222804,
 0.8056482572812261,
 0.6822734926957139,
 0.3027385160880486,
 0.7700904088178042,
 0.7996824148607594,
 0.5010650841935518,
 0.14280346890439977,
 0.37544793954690425,
 0.17706388628137526,
 0.13694798145983167,
 0.3013809181286585,
 0.4884939308512879,
 0.8012150253046723,
 0.601087481778529,
 0.2670267959539461,
 0.9168776704380605,
 0.9492696779292712,
 0.859817853143562,
 0.4720016068128764,
 0.8718822994490795,
 0.167508371665549,
 0.7919885772410453,
 0.23028505923134335,
 0.2497506123330493,
 0.06681626488752579,
 0.8255569797469022,
 0.8158017816362514,
 0.830508433096534,
 0.5613888075514656,
 0.14487123473746488,
 0.3940661846310618,
 0.21786780805203487,
 0.5604376012266448,
 0.14617660582833325,
 0.21205850200813903,
 0.724362043129719,
 0.6181105033544306,
 0.6795927509803347,
 0.5184361707760895,
 0.34628353925182875,
 0.19130829454310638,
 0.2236474144673294,
 0.5533603654547542,
 0.01765623597218846,
 0.36317100984349693,
 0.4402677732438318,
 0.6824989301208209,
 0.0110705749269977,
 0.4223496727406294,
 0.42172042527534426,
 0.9430441850018226,
 0.6484843759454824,
 0.5185364056327332,
 0.7570479928467997,
 0.7716854779137813,
 0.780384016930683,
 0.5636235735180172,
 0.3054766838912545,
 0.5908043609340922,
 0.0201897493905,
 0.6982046855000986,
 0.12341539504918553,
 0.9694899875843277,
 0.5719811235094897,
 0.7592428493863296,
 0.39522442533941216,
 0.2093800011433773,
 0.43131373369420756,
 0.11152307657708382,
 0.41261849685004726,
 0.8567408932306207,
 0.6095774104621675,
 0.9125135003463087,
 0.7209452492629408,
 0.7868537319492106,
 0.7477378156630106,
 0.2295672059333238,
 0.06326936567311692,
 0.3799296247439945,
 0.1270107497888382,
 0.6748421155050275,
 0.02876831848236905,
 0.5084143956001275,
 0.8005802428325227,
 0.7300044336745367,
 0.017684675109961967,
 0.04518380322724902,
 0.946891974517918,
 0.030420874860244584,
 0.7541719324018353,
 0.88307434456488,
 0.2306997243467842,
 0.6226473710684235,
 0.5760969226195255,
 0.8929990030423042,
 0.2433948401036723,
 0.4589723883201632,
 0.2633482155295638,
 0.4174312997140561,
 0.7415494271495843,
 0.5222372330260469,
 0.0095353492408069,
 0.2921326818615151,
 0.6544920826410646,
 0.9546890007588287,
 0.594751076438261,
 0.912778133046193,
 0.7005117761530414,
 0.6525184535037922,
 0.6289396266539716,
 0.6061032973207813,
 0.920496523514758,
 0.42478606225873017,
 0.43475165699997864,
 0.339054022875829,
 0.2868250822231797,
 0.09404329922096699,
 0.8886649614570272,
 0.8333008853865872,
 0.7340698720439484,
 0.5698523737229613,
 0.33540790515911567,
 0.527471301765135,
 0.6015825572461778,
 0.6584049150447872,
 0.4083156209134272,
 0.4422188440287306,
 0.18267878447361896,
 0.10664742853834319,
 0.9009445422705774,
 0.3312134642286392,
 0.5876393505792866,
 0.9736359829908658,
 0.19011862319210637,
 0.5177131526189416,
 0.39639391816988945,
 0.3179435111261061,
 0.5128709683224871,
 0.6375703055829179,
 0.9464149107967748,
 0.6415760118088292,
 0.33035092027185264,
 0.7261089148670853,
 0.6138932293796989,
 0.26208153998900396,
 0.8702981752917146,
 0.07634726214212684,
 0.9121191099488895,
 0.450659504385855,
 0.6112573585039373,
 0.01051129663699879,
 0.03634012932090602,
 0.6101881356261412,
 0.10791686777803788,
 0.6641842830621955,
 0.7009335201347747,
 0.17910016269381202,
 0.5733982551209326,
 0.2668424286116251,
 0.8305786898243752,
 0.7542579589750992,
 0.8203003212813905,
 0.31042995734635015,
 0.9375219093339507,
 0.032288846838640084,
 0.5728203478742773,
 0.33740658957697733,
 0.5425153400207278,
 0.7388805688360214,
 0.08788293986467888,
 0.7705550360962145,
 0.9356962077202002,
 0.7759645380062407,
 0.01681993952620131,
 0.0841294603639906,
 0.8423558868289397,
 0.5575785607911106,
 0.3454474480378029,
 0.6805781023951223,
 0.8159726219712029,
 0.6096880344625663,
 0.018050330809324944,
 0.4557124457327404,
 0.21809914021719512,
 0.34842826908610625,
 0.3346853655038632,
 0.3882555988062927,
 0.69545234810587,
 0.031239279577523815,
 0.13365112581227145,
 0.3583236016740744,
 0.7446543062175113,
 0.09643012331217549,
 0.2662466285279854,
 0.15853372239774788,
 0.6185597504654807,
 0.5602271751599506,
 0.49373946039568717,
 0.08221565561845279,
 0.7892650883519209,
 0.750963966812146,
 0.6741555806999812,
 0.8387993202949273,
 0.42047429766183686,
 0.31487243020518785,
 0.5417121661152742,
 0.6245018158771557,
 0.5744831728135029,
 0.7086303042127726,
 0.17122839856904482,
 0.4325372628942846,
 0.4995538417635813,
 0.13965197190159895,
 0.5008807902502822,
 0.47606821147007794,
 0.5757152839420789,
 0.30518124677220504,
 0.2768697608988542,
 0.14291043101086354,
 0.13143976743342778,
 0.9933335758424895,
 0.6631429334732383,
 0.99252803480768,
 0.26122681510928647,
 0.3114842940038747,
 0.29528869813445524,
 0.15498213174535413,
 0.6326276330717336,
 0.9643870423744398,
 0.45545633925911666,
 0.26139552458774196,
 0.3687024479104628,
 0.049784011448027354,
 0.34778660265730343,
 0.7880545093162782,
 0.7038243397141632,
 0.0087725557899887,
 0.037447290102236686,
 0.6138467588017014,
 0.18951028940001924,
 0.8250327533333768,
 0.9737373693871371,
 0.6521867728441003,
 0.6763417249845671,
 0.8024069836903883,
 0.3162263482565122,
 0.9252704349241536,
 0.9082050873670564,
 0.4156587069691825,
 0.9358060727780322,
 0.44559419639048004,
 0.5189950395838209,
 0.9576739192286606,
 0.6317311645767333,
 0.3345182110142617,
 0.19497746817202366,
 0.9484391284585596,
 0.31530846725993256,
 0.40298196392194474,
 0.36509412053676105,
 0.4270804248487633,
 0.38879600035878414,
 0.9415501759095275,
 0.6748053750530599,
 0.25693756873105145,
 0.9323161092205331,
 0.6075640631430124,
 0.45429279333611416,
 0.3589511752196102,
 0.5084271333215404,
 0.9365338300446695,
 0.18307001190048666,
 0.37707002884139795,
 0.45423143793538034,
 0.9183988394765453,
 0.8339674611123865,
 0.7794429578082288,
 0.13262910572473363,
 0.37554986256709133,
 0.9252638024987598,
 0.4110478530098576,
 0.6091306799476214,
 0.254082718665568,
 0.32651054527795675,
 0.4420048809700444,
 0.3137780419841537,
 0.6625797981311894,
 0.6254007499340251,
 0.8104303417041719,
 0.7203729810087701,
 0.5601324606754917,
 0.17628788504309512,
 0.44952952310745664,
 0.7595863884442502,
 0.4506553343750046,
 0.1640904808251159,
 0.45569229765689534,
 0.49026252981348806,
 0.6653246186022641,
 0.8452164608824753,
 0.058003698583885654,
 0.3009750973519476,
 0.21189127399762964,
 0.13264745780229692,
 0.937785168133729,
 0.5792614971934905,
 0.1893332239441543,
 0.9768589351032415,
 0.8702205664631075,
 0.3728907918542673,
 0.2914909808387748,
 0.5794060046868029,
 0.4357506392481082,
 0.4696132619107821,
 0.9440499711165518,
 0.5758026806913776,
 0.7658351546337466,
 0.9598283424300511,
 0.09598513552047849,
 0.995287255636835,
 0.972691227552249,
 0.8580923978546316,
 0.11488273067367671,
 0.14657306659046898,
 0.12965793255015168,
 0.47118478544342657,
 0.8662445031502897,
 0.8775432524259065,
 0.021026470372736417,
 0.7793711274337928,
 0.20600611816996972,
 0.31360431297653557,
 0.2563803986679998,
 0.9067546258062235,
 0.4237915775623182,
 0.9809359595122843,
 0.2945904555470703,
 0.3596438128434346,
 0.23039948242762454,
 0.31367161905776797,
 0.20507287005817854,
 0.30069207870010206,
 0.7419035464645207,
 0.5285668922583844,
 0.9843793560910197,
 0.5257050878840226,
 0.7325766928874279,
 0.2567717875952118,
 0.9562754169734682,
 0.684656129526298,
 0.1850842186608297,
 0.6085450799827081,
 0.03946073958627505,
 0.34285443855725295,
 0.5131256530328365,
 0.6111731332614887,
 0.45467047959704243,
 0.12300888029736623,
 0.0810196083622644,
 0.6615022368342967,
 0.6352366985189692,
 0.5194627777857176,
 0.10573389165551783,
 0.32368634742796953,
 0.9242470740774178,
 0.26837832839696485,
 0.971943229756178,
 0.3765953258179109,
 0.40646947066606987,
 0.027403366759831016,
 0.2219536281570902,
 0.6474819967876123,
 0.5641609844229045,
 0.7840114600256589,
 0.06348649846441645,
 0.06322314231909665,
 0.37235047194310467,
 0.7171632340420743,
 0.4893632906739871,
 0.6491090212753812,
 0.00024384024076062882,
 0.8228203879247991,
 0.6193074549473672,
 0.6735415251562622,
 0.8645860969227834,
 0.8061646577609337,
 0.12037486869756675,
 0.27788909156841146,
 0.5553646740458275,
 0.9457962008714941,
 0.2550819888257445,
 0.29815061881516036,
 0.7895346405785071,
 0.06315089818589814,
 0.7446984619770501,
 0.2911292190321162,
 0.6711092059303246,
 0.34190941172943645,
 0.47516900296301834,
 0.638286918259047,
 0.03745162827018467,
 0.4168074767327994,
 0.8848813423937263,
 0.7454427023656152,
 0.21175039714633037,
 0.725805343686408,
 0.7854101976193811,
 0.012251545887896342,
 0.8995851755988589,
 0.5306053381242777,
 0.6406707616938152,
 0.46874151384627494,
 0.2724655600873931,
 0.7335822285328588,
 0.9999733260006006,
 0.5852521499302547,
 0.05420025137431639,
 0.6034036160054967,
 0.42214714860761404,
 0.9507077342892956,
 0.4470948046860975,
 0.9891807901506623,
 0.9011901734888152,
 0.03880425711423541,
 0.6274906254954424,
 0.2624327317515637,
 0.20977753875546934,
 0.6062522336819521,
 0.9093985213621759,
 0.8045185621628255,
 0.025884972427135722,
 0.6476408402835946,
 0.7325172804077126,
 0.3380951739976098,
 0.9256534839800418,
 0.9776693126088852,
 0.08049710908708063,
 0.1163337595036954,
 0.45205174282494753,
 0.03164372743554189,
 0.4032658163067101,
 0.3970748093313706,
 0.8219945573492077,
 0.753078253571238,
 0.7343725139578686,
 0.6622611477074957,
 0.8223972687296006,
 0.33763708962372585,
 0.06153040299634338,
 0.4181921224596403,
 0.4093111861018449,
 0.662246094825545,
 0.4446152268233461,
 0.969676263050215,
 0.6719671968530639,
 0.5111902707741843,
 0.36294146521499926,
 0.5059586363513354,
 0.9502456397798005,
 0.5732032780552454,
 0.3268758333356355,
 0.9622987210632516,
 0.5661472923040538,
 0.4875559070047165,
 0.8606559523325045,
 0.26845313228905354,
 0.35946265567395863,
 0.46790676060816516,
 0.9715590931881397,
 0.14472983170654308,
 0.9599842040991751,
 0.8691521741933325,
 0.27420875735912764,
 0.8553067169429316,
 0.9083988059650765,
 0.8843735079137351,
 0.4554142914935475,
 0.5791093080409173,
 0.26862435990755895,
 0.0892000388964228,
 0.5785424526887931,
 0.8364014107481096,
 0.4784271847333039,
 0.3225537050090367,
 0.5308396501598882,
 0.10114051362476517,
 0.5394446332370348,
 0.24716775142611813,
 0.20874149419490906,
 0.09598494618155073,
 0.8106422155905344,
 0.7703683850635727,
 0.7172076577725316,
 0.85494208406912,
 0.8041409274348162,
 0.7034846150392597,
 0.19673464144948527,
 0.8348331967425715,
 0.9871844093732173,
 0.8808817128833774,
 0.7637476912603481,
 0.6505165842039389,
 0.34878105941039717,
 0.2789266995085563,
 0.5139475232715311,
 0.6511253303492527,
 0.04072447513986688,
 0.46623321573778576,
 0.04129794556850752,
 0.027210624486427082,
 0.11124776789267432,
 0.8952943183336416,
 0.1797446851706601,
 0.5199271791890027,
 0.42908563319621196,
 0.5980743538788068,
 0.8181296275003478,
 0.15962479480403124,
 0.49267432666888455,
 0.07014392691439397,
 0.9723799217453626,
 0.07702085988745444,
 0.19573701428075674,
 0.456177339673858,
 0.4611853256025036,
 0.11321433252590174,
 0.6687695793643412,
 0.39112388858253144,
 0.9220190033410705,
 0.28132229515196927,
 0.07332308903003715,
 0.9607093127392116,
 0.034434031840022694,
 0.5236082934668419,
 0.307968412678731,
 0.8751963956834742,
 0.15193862838625227,
 0.2585556916760483,
 0.6893928492759116,
 0.5308223361141909,
 0.32467380890900954,
 0.24212007409214376,
 0.4461839197784885,
 0.5291874374481832,
 0.9346071414863121,
 0.3990982013065908,
 0.1180923959863126,
 0.9125507233951279,
 0.8110319667176951,
 0.7085169270855137,
 0.060866390598868114,
 0.5787457279783306,
 0.38738847005383636,
 0.24533228127325413,
 0.8982926738930512,
 0.7521585388810034,
 0.8091995173891897,
 0.18981129821182663,
 0.13495020752271847,
 0.9346611955994226,
 0.6916194995745262,
 0.013960471460522927,
 0.30167924818626857,
 0.5225741878549308,
 0.13002727226621502,
 0.568516959418914]
  • Normal
In [6]:
mu = 0
sigma = 1
random.normalvariate(mu, sigma)
Out[6]:
-0.5120344186633362
In [7]:
mu = 5
sigma = 2
random.normalvariate(mu, sigma)
Out[7]:
4.772935466104815
In [9]:
mu = 0
sigma = 1
[random.normalvariate(mu, sigma) for _ in range(100000)]
Out[9]:
[0.9836782518477859,
 -0.1279101687591586,
 -0.3624403898225458,
 0.7827052278831221,
 -0.7070779863207516,
 -0.6448080239634407,
 1.4456726257278167,
 0.06320794089168544,
 -0.29753597708213325,
 -0.32560560777628234,
 -0.7230778730855582,
 -0.13076016750403674,
 -0.30061745241957266,
 -1.0659338448280822,
 0.18702539900575452,
 -0.5687484200779066,
 0.3649845859647074,
 1.7494040278146015,
 0.22600474005569396,
 -1.1151380585639925,
 -0.19273145821820742,
 -0.1894484224252513,
 -1.2991944916491394,
 0.0014470309434913397,
 -2.016619191103081,
 -0.4868974368345301,
 0.38623594444235065,
 -1.0279664100736308,
 2.0696667563512854,
 -0.21915509444362868,
 0.05837508542557953,
 -1.0421644744582546,
 0.520337034045725,
 1.6298123466140946,
 0.2731902531856528,
 -0.49626275975376827,
 0.7213906936670386,
 0.4689259813211926,
 0.15933457854920816,
 -1.7959849130370746,
 1.3045111181234956,
 0.7813604382974706,
 -0.4904504866798668,
 0.052711516960373433,
 0.37613597276846417,
 1.1888089622841818,
 -0.315381760539186,
 0.7352713201680545,
 -0.9287964829079589,
 0.6313662822093423,
 -0.002643011195867273,
 2.201762301567866,
 2.159310700624468,
 1.6204783537726408,
 1.6585943948387993,
 -0.012079923573957534,
 0.17552772814930823,
 -0.7553920347786057,
 -0.1264752552589199,
 0.286211602008681,
 0.761494007753402,
 -1.1645526453411081,
 -0.3794302666082327,
 -0.1384013117251106,
 -0.08239327965834849,
 0.19706985000355312,
 0.1132265247031994,
 0.47107137834889334,
 0.3875399336511707,
 0.8459857793782015,
 0.336353155188211,
 -0.03475658463368482,
 0.9570217760520817,
 -0.4916282032068359,
 0.26315750711268354,
 0.05643176125553084,
 -1.6406655427172665,
 1.9785088595151974,
 1.858298853642196,
 -1.1378657647404746,
 1.7381069680154402,
 -0.586855432532685,
 0.8669821665136328,
 -0.5407068819993033,
 -1.5943090601816199,
 0.5109704749722568,
 0.42170622787092804,
 -0.023814590202878586,
 -0.17225696601606771,
 -1.3164152535583546,
 -1.2004526696873363,
 -0.11216373634386578,
 0.2958962316454557,
 -2.093761149756984,
 0.3700416584115787,
 0.4711892963041232,
 -1.8814273250721547,
 -1.6119077072365928,
 -1.0061349572434817,
 -1.3689486386433063,
 0.4534943095450973,
 -1.4897540979531854,
 -1.113007090216175,
 -0.40038238410040106,
 1.626094987171871,
 -1.2057940679877142,
 -0.12748234983330223,
 -2.6330386956332554,
 0.5400302368454897,
 1.1289308011781276,
 -0.6502497080523407,
 0.2948858799195664,
 -0.9141219906789654,
 -0.5246967489229235,
 0.4972172257271628,
 -2.266821037575801,
 1.069621727855683,
 1.1295672305426248,
 0.14098791272878514,
 -2.0203969673109956,
 0.30965130363821153,
 1.0475003943491064,
 0.460810630754534,
 -0.7154329322217877,
 0.8154913156613197,
 -0.6812762800319565,
 0.015075297176729572,
 0.7988787136439107,
 -0.15209765898769792,
 -0.7712605766301307,
 -0.30728420749033447,
 -0.5107092435567145,
 -0.866201772447652,
 -0.25048561521563634,
 0.061776718312786125,
 1.531532831577984,
 -0.8341467240751311,
 -0.008133872920113982,
 -1.600496455233334,
 1.0273661547442785,
 -0.7585133601897703,
 0.011012278993023789,
 -0.28430157751809143,
 1.543603927428709,
 -0.18490448848644417,
 -0.9548956944784334,
 -0.7790878983480789,
 1.2645985785356653,
 0.21458666357321965,
 0.24165718062971245,
 -0.4303503683480948,
 2.256778899687406,
 -1.622709260021866,
 -0.7407745329988508,
 1.1202977469205808,
 -0.8323383406496541,
 0.5909952900245135,
 1.3678119524222927,
 1.136601011029377,
 -0.8286235985010088,
 0.4383832311661699,
 -1.2586391761509368,
 0.0015953715639482346,
 0.3937880709323745,
 1.690080883037178,
 1.7142638599668345,
 -0.27430240660796906,
 0.4925893574590412,
 0.655191541660535,
 1.0649978685704051,
 0.8149690070439966,
 0.7500695406250937,
 2.3625641964221327,
 0.004197274108459031,
 -0.2304461056770102,
 -0.12620099266634632,
 0.705821123332996,
 -0.3777984624345596,
 -0.6468572099273453,
 -2.063681469473497,
 -0.1372535847333382,
 -0.09496005945037288,
 0.3441579971874162,
 -0.7728175461078481,
 0.28846860867943797,
 0.6879938484824597,
 0.056005798513395905,
 -0.2055686088739486,
 1.6672366916409695,
 -0.8874377034751618,
 -0.45845854008941417,
 0.645138148037618,
 0.1966782732911832,
 -0.8512012331970201,
 -0.6793600239205759,
 -0.6528320167262023,
 0.13122676482544418,
 1.4559627025357318,
 1.0156200487244544,
 1.2244331516798503,
 -2.1231477610144225,
 -0.2687645285703345,
 0.7674508402142546,
 -2.056638991743492,
 -0.3190611661928917,
 -0.3626067186457122,
 1.1566441956745077,
 0.39455945285931826,
 0.0814593982398023,
 -1.0451548498312873,
 0.011326049288669213,
 -1.4551321720365606,
 1.803053603839938,
 -0.21856207190052823,
 -0.33808138940239424,
 2.0526131514321873,
 0.9472149131054023,
 0.10454036571254358,
 -0.6441034810534149,
 -0.992004408193634,
 -0.3479456997793678,
 0.09771318961953214,
 -1.892120916851502,
 -0.22828518702644665,
 0.17865745120542043,
 -1.4658604659621823,
 1.2028508077266686,
 -1.3763074612676325,
 -1.9516618500759095,
 1.1071969921890283,
 -1.0290820386676611,
 1.0344760046839545,
 0.3732277762411952,
 0.8369649932762416,
 -1.640400668286347,
 0.704660292404816,
 0.6979555581592255,
 -0.09707760731340563,
 0.012035568163329683,
 -2.7946804946367174,
 0.12099460182548923,
 -0.877440621744683,
 1.6293559975740461,
 0.7628077033474459,
 -1.3830082038508063,
 0.6432073621572711,
 -0.4808197450458627,
 -0.8472496851846738,
 0.5406039573791094,
 1.2891356058411854,
 1.1045851757812137,
 -0.9208726808299171,
 0.526849664403746,
 -0.7076151233553573,
 -0.5332481823368691,
 0.5188354620689489,
 0.9882321856703198,
 0.00992943939988886,
 0.46923271290784413,
 0.23503909982347299,
 1.8823494223254564,
 1.4212515978117837,
 1.0638955144737998,
 0.2896842993862823,
 0.9411995125970596,
 0.6371847406417338,
 -0.6844735558405933,
 -0.1730246678906839,
 -0.3512566687602138,
 -0.7330945536060564,
 0.3634928294050906,
 0.7331385156979504,
 -0.6693659476036994,
 0.8710967894425101,
 0.6060810804328493,
 -0.24432596565370776,
 -0.4671728465789112,
 0.1976751901395088,
 -1.592216916375199,
 1.869305018041527,
 -0.8536449678513445,
 -0.4595383431488887,
 1.731334139448684,
 0.46077633958741687,
 1.2598450448026597,
 -0.02870184271213124,
 -0.2756998403493735,
 -0.30055996752042685,
 -0.32820396446486505,
 -1.2320683567799953,
 -0.18238078656759643,
 0.19719008400007532,
 1.1740981491156919,
 -0.49468293301503286,
 -0.2600672294481035,
 -1.0364993630797505,
 -1.2556697483358914,
 0.653314561236705,
 -0.5109217560741065,
 0.3177739972318694,
 1.4145846120388708,
 -0.8287531099675675,
 1.2219295816903835,
 0.13761976801339962,
 0.3451480090978417,
 -0.9794785501902179,
 -0.8240690060133199,
 1.1139455078854335,
 0.7358518891327797,
 -0.38015826202472974,
 -0.10610292914756209,
 0.9750006652237427,
 0.6009351245225066,
 -0.3501161759412183,
 0.2699799905124518,
 0.8176326743454322,
 0.7373213776521914,
 -1.1541279253143217,
 -0.030038865868709352,
 0.7968815641243445,
 -1.2468922718489706,
 1.1961887146241854,
 -0.11433187296554324,
 -0.24271826247391165,
 2.7587592415836144,
 1.748707489736812,
 -0.6433595207571287,
 -1.4799210052450502,
 -0.13518779863971941,
 1.7122986346009088,
 -0.6196847323026388,
 -0.3933479522511165,
 -0.9551532392442089,
 -1.0462878046301838,
 0.20728286653054806,
 1.2929460299574775,
 0.5642385266750364,
 -1.1337116597994112,
 1.0106477727080232,
 0.178087683615388,
 1.244306625411806,
 0.47549317541189345,
 0.04227752539948481,
 1.5622046191403145,
 0.39175884510983666,
 -0.3619412303199644,
 -0.7168412875981013,
 -0.4918957394195832,
 0.9375836720081077,
 -1.1897164359661114,
 0.11245565973739334,
 0.5625910847508155,
 0.46578087175894056,
 0.7143260489524439,
 -0.0075793554743260145,
 -1.7807179609521795,
 0.16515502868251528,
 0.6667542748123468,
 -0.6871529346099333,
 -0.03458684910565041,
 0.39075815923976365,
 -1.1609001886275179,
 1.0025600145002982,
 0.10050874426390079,
 -0.49531795660270417,
 0.7357329904214688,
 0.06683848685074721,
 -0.0978032613327617,
 -1.2400790705425764,
 0.32255405829301553,
 0.008258283674373043,
 -0.33021128919414117,
 -0.09174351087706682,
 -2.655598644947513,
 1.4761373139803071,
 -0.8434756141716114,
 0.03773941334934189,
 -0.880569277035666,
 1.193147230777026,
 0.13065182219648597,
 0.40582650067317944,
 0.9389429616646158,
 -1.392332141877377,
 0.5902413266000184,
 -0.4426132614988029,
 -0.9509477439944335,
 0.1387268040367014,
 -1.2004604844365834,
 -0.7595003090582371,
 -0.17136436586455298,
 -1.6855929221166237,
 0.3197279133914426,
 1.2734800317815236,
 0.03219808693196488,
 -0.6561705969921644,
 -0.7248424488022353,
 1.0269063982140023,
 0.5274696245724194,
 1.3480796308385818,
 -0.016350608641472822,
 -0.8763972017218918,
 0.6721337088522384,
 0.4739818274750511,
 -0.12871044907208634,
 -0.4176409768485201,
 1.8523059943702578,
 0.8180674171976724,
 0.5398103076698806,
 0.7701608602730478,
 0.27207054721100743,
 1.2907993679226342,
 0.5180907133221518,
 -0.1476463683352946,
 1.3792384398637578,
 -1.1829559862819912,
 0.19292840246120663,
 -0.2931465899734277,
 -1.3077456100393858,
 -0.4714951977339859,
 -0.15815627713773694,
 0.4335093224825212,
 -1.4408548056756927,
 1.5725681332501447,
 -1.0579780613429055,
 -1.5196576478201758,
 -0.23922576949906796,
 -0.16155921921301983,
 2.4086348793801866,
 0.3187742524313938,
 0.5551899594151579,
 -0.4992564886147928,
 0.058462431898517825,
 0.3102315462766692,
 -0.4666518631710002,
 0.1777821557906603,
 0.6916649329644352,
 2.365377434954345,
 -0.438085437366895,
 0.5933605572968529,
 -0.5560928634094746,
 -2.140005652792525,
 -0.612311577525075,
 1.1042429695561926,
 0.3815186621124146,
 -1.5591305282299683,
 0.2569062291207094,
 1.5638191067782599,
 -0.12217072341070574,
 -1.3952281127531845,
 0.1316507932202826,
 0.5414998864841283,
 -1.0255573760400418,
 0.06098663815293411,
 0.5036124226351514,
 0.46948828740663096,
 0.8411851705045064,
 -0.18633495114483625,
 1.0109557252515085,
 -0.7771719585008464,
 0.6317987234725453,
 -0.15177054080658428,
 -0.18644004629511673,
 1.0904542536746376,
 0.9000222082640035,
 1.0077242787434855,
 -0.274570414630451,
 1.1539723395769839,
 0.4653713082423597,
 2.29470568288725,
 1.0230112688923048,
 0.37757217458131975,
 -0.13479167908360243,
 -0.7451689110411678,
 -1.1459264207576931,
 -1.6741615943977575,
 -0.2156446977288552,
 -0.24336585664790064,
 0.3316959505773565,
 -1.4155535637123922,
 -0.03489269699645882,
 -0.42780342217857253,
 -0.8919099641181027,
 1.3683274042677067,
 -0.37049130610855907,
 -0.639730251590133,
 -0.7137566723622106,
 0.49776393509930467,
 -0.5440904879647656,
 0.38627262733674655,
 -0.22523897307100846,
 -0.030832719001928313,
 -0.8986408628796582,
 0.7890238242991096,
 -0.5806458387932498,
 0.24109692829243654,
 0.6750420641258875,
 2.0788894407698653,
 0.08694262740105503,
 0.12992829957047974,
 -0.6290204700985443,
 -0.08751365478603511,
 -0.06418411664774862,
 2.158045243155661,
 -0.421376554095992,
 -0.261800065387016,
 -0.0775508839434278,
 0.6025132870117234,
 1.117804880079807,
 0.20440217982488873,
 0.5798029305654818,
 0.734358830152325,
 0.2851907575511466,
 1.848276999605566,
 -0.3836202253921756,
 0.1905938484845794,
 0.038311720066513594,
 -1.6828333457213904,
 1.3309916525735186,
 0.31655660296050303,
 1.9307869653596736,
 0.5330173758688395,
 0.08611569446315853,
 -0.5860753877931218,
 0.8214629153840906,
 -0.2764361306496533,
 0.23140928351173062,
 -0.5169312520338957,
 -0.864207811825662,
 1.372547406176277,
 0.4041669876030419,
 -0.8783212552281661,
 -0.6203989896476078,
 -2.0045046854595703,
 -0.045138884356252615,
 -1.7929608616794719,
 0.6662102027696337,
 1.6130605868507295,
 0.21052185817287186,
 0.8264406552562388,
 0.9752893759001801,
 0.4966578801353016,
 -0.16798167096026353,
 1.5528975764992987,
 0.23685540155869686,
 -1.3715260925467312,
 -0.26184285755953335,
 -0.3383138176846999,
 -0.6334202830395843,
 0.630310827981342,
 -0.3635147413420678,
 0.8112714383746542,
 -1.8828925792143782,
 0.3092629838585712,
 0.14423449466353197,
 2.565100506493693,
 0.056351560158421056,
 -1.1035163150943694,
 -0.14555239233344766,
 -1.2143409186730334,
 -0.7637150988262159,
 -0.02891378449266582,
 -0.6591141312937652,
 1.2859492445818324,
 0.1283565391954985,
 -0.021550672753253508,
 0.9945351237522292,
 0.4977225780035918,
 -0.9115925047045681,
 -0.7436056067563329,
 -1.2128402746642415,
 3.0773628166676876,
 1.9274108027483015,
 1.715322009462595,
 -1.9579010692269898,
 0.31803633823926875,
 -0.37057875790229733,
 -1.6879802451854413,
 1.0142330616633988,
 -1.2200509088491265,
 1.1932898350216046,
 -1.807342788377936,
 0.12814068747946059,
 -0.7442984307299365,
 0.43690906451819056,
 0.06495718548609807,
 0.7786995588761981,
 -0.310221566910865,
 -0.6979927185508589,
 -1.3769903846264109,
 -1.349791086119963,
 -2.209197622019654,
 -2.450819271680675,
 -0.4290123222057186,
 1.5125357627668612,
 1.8519826645754869,
 -0.6115411464107035,
 0.10236212849205625,
 0.7117324899911512,
 -1.681254273556694,
 1.1436728666765916,
 0.0976337573404756,
 0.7458577735683755,
 1.057728618208621,
 -0.8033781736308381,
 0.5218334423005917,
 -0.7816909289385433,
 1.0253418900448512,
 1.0837502289265002,
 0.15547226641858372,
 -1.0905617692894924,
 1.1876468157452338,
 0.33220219961233055,
 -0.6111808245786217,
 0.5057857309562543,
 0.5973304551854067,
 0.05731077454284249,
 0.07142266446035837,
 -1.4357773778722496,
 -1.1038208878050557,
 -0.7462913144097424,
 -0.0029678514263069464,
 -0.8677233369359735,
 -1.5524595980444014,
 -0.8477949671585071,
 0.9334773319859906,
 -0.26927736053175305,
 -0.9684800072105568,
 0.3881713025264866,
 -0.9347283424077778,
 1.1580331250121654,
 0.4822942380841192,
 -1.7263568982414814,
 -0.7855511274020607,
 -0.8423662860471253,
 0.17793560737045763,
 -1.206733830165843,
 -2.204884705435333,
 0.19952557273495733,
 0.9955880052522396,
 -0.2476815863455215,
 1.6135163050181907,
 -0.0843077529982479,
 -0.6490547417526823,
 -2.132172249190846,
 -1.9999647760306767,
 0.8786809251432721,
 -1.1878776131182445,
 -0.7585509387426225,
 -0.01719873805472759,
 -0.7067548453777415,
 1.696163536486536,
 -0.9656230908870055,
 -0.08487758175575745,
 -0.600558266285011,
 -0.7112338091820719,
 0.6782759177160311,
 0.014510732172898678,
 1.0038795036700334,
 -0.3745292665397835,
 0.2692418679962379,
 0.4908647428537253,
 -0.1959623905101818,
 0.1826908490379934,
 -0.05095588743072958,
 0.6246665288192419,
 -1.0550206523033747,
 -0.15790317616811306,
 -0.31540750080207364,
 0.7206861435775914,
 -0.5833717336011887,
 -0.45397992606214316,
 0.16420995840782654,
 -0.2573393338598271,
 0.18022012233048734,
 2.131427627010072,
 0.3017055724341678,
 -0.399674733223173,
 -1.8488849985921962,
 -0.6051152248175736,
 -1.2677802145695338,
 -2.405969475207709,
 1.9770063621281455,
 0.22281450098301608,
 2.231519850720209,
 -1.6617689256137993,
 -0.5565608146290341,
 0.46958420862631645,
 0.5104191768167441,
 0.21348709122516057,
 -1.1617557661521214,
 1.0935461595034692,
 0.7773203467559692,
 -1.1215996295957358,
 0.7600423316276269,
 -0.9110324511419643,
 -0.36422960690291456,
 1.3235728629695633,
 0.9277325919657756,
 1.2476779650968743,
 -0.9974270289350738,
 -0.6974994501314833,
 0.8330580370856001,
 0.7784558389993258,
 -2.207444552129134,
 0.24048182442880717,
 1.175076404151108,
 -1.3514504889480148,
 -0.07132431042144047,
 -0.6121694132957829,
 1.5479341344157072,
 -1.024298834708817,
 0.23203674310625635,
 -0.6208381474760492,
 -0.8168513917829292,
 -0.867951673873998,
 0.19344861199273927,
 -0.3287910319661375,
 -0.04301907850243098,
 -0.33458296455075215,
 0.25213754613061756,
 0.05509588704199383,
 -0.7733593714781789,
 0.8522295192445088,
 -1.3379180467260259,
 0.8244064101527337,
 -1.499691948785239,
 0.2040511918698077,
 0.41561849413450846,
 -1.1520357207461684,
 0.15165912725682804,
 0.38039078856001535,
 -0.7827815361572551,
 0.1372928427847984,
 0.2357147133794898,
 -0.6684781655309822,
 0.1093617851393221,
 -0.5362308595655637,
 1.5344691122861287,
 0.4796299592666926,
 0.22135748073466507,
 -0.5295059564209675,
 -1.586617399080973,
 -0.5698047734895717,
 1.8471705829192824,
 -0.829372263379086,
 1.5996221938083213,
 0.6890083419326892,
 -0.09075624188517642,
 1.7189495153312746,
 1.677103310374561,
 1.0560779195167753,
 -1.0037856177173363,
 0.9201566510102458,
 -0.15034192811859376,
 -0.0028178086011071807,
 -0.24552738756637468,
 1.4533104641293906,
 -1.0935457751838888,
 1.1303171062460298,
 0.24451673401520965,
 -0.2261492579789665,
 -0.06686562078933343,
 -0.1904882705807079,
 -1.3985850662240336,
 -1.7399248824436107,
 0.5838049521862241,
 -1.1893580028580797,
 0.5169694746790467,
 1.1207910525309555,
 -0.05026405547129305,
 0.29791071281521625,
 1.0629766565676195,
 0.8668611508086796,
 -0.6700373879301587,
 0.9897474256809436,
 0.627774650878914,
 -0.8407566012421911,
 -0.5519009551310861,
 0.5954872458376667,
 0.29312285381810027,
 -0.04168062629030736,
 0.8101300960539274,
 0.25682654522848447,
 1.037260347457185,
 -0.25662248292076045,
 0.3377751389817152,
 -0.3687202029512831,
 0.9370506181328536,
 2.1291185701480213,
 0.7978613582437124,
 -0.8106243875983968,
 0.30886433579921047,
 -0.0869662428258486,
 0.7079075731465176,
 0.33780524348638696,
 0.401044250220524,
 0.5855754138459665,
 -1.699343668818625,
 -1.717063633595529,
 -2.7535525374213496,
 1.1823033529106475,
 -0.39378526540049025,
 1.4695009604845144,
 -0.07811956736989832,
 -0.8275605758547856,
 1.7849577413764608,
 0.43818824701650255,
 0.9678572169299147,
 0.005516430055135316,
 -0.5148820621506807,
 0.9215489361016802,
 0.9090150305803869,
 -0.4534181424508387,
 -0.5550603632060109,
 1.2112480256304303,
 -1.6125889503040765,
 -1.1830731777007986,
 0.3362808412473585,
 0.8680635898650315,
 -1.1418737046122656,
 -0.707412054398964,
 1.094398632193233,
 1.473665121018776,
 0.5578397659545642,
 -0.21473327233531395,
 1.9991489502738227,
 -0.9849813808560608,
 0.7217943417923133,
 0.516624984261349,
 -1.907036617590653,
 -0.21639819190609808,
 -1.1714415270670475,
 -1.2318734157790023,
 0.1455395097548322,
 1.7399333038746847,
 -0.15628660029218128,
 -2.0578467525886213,
 -0.030271600206837678,
 1.6614185920583533,
 0.2363220510609827,
 0.7929922087039537,
 -1.3841680355039296,
 0.11390202015874136,
 0.7367484926181976,
 -0.577182871553991,
 -0.7762545594148229,
 -0.5218642595552805,
 0.8835266491927789,
 1.3303786905890915,
 0.5016510300943917,
 1.146262504893712,
 -0.9450922458454633,
 -0.3136079734307819,
 0.9128800265176598,
 0.23613481003092043,
 1.2721940055893965,
 0.9392671642876806,
 -0.9112256115842141,
 1.3845580335066523,
 -0.9715938540577749,
 0.2075087252374109,
 -0.5310392473003962,
 -1.5546607489634434,
 -0.7135364416561645,
 0.2964527768189438,
 1.1972872727447572,
 1.0003942515895397,
 -0.5545299853571596,
 0.8207503164121972,
 -0.04925663854759928,
 -0.5686073084364326,
 0.007682777210818868,
 1.4953652772109525,
 0.09489464976045094,
 1.4001216512092176,
 0.37811418498142124,
 -0.25067407721852936,
 0.8256782537619141,
 -0.7439754409093267,
 -0.16315686076975072,
 0.9142328508589719,
 -0.43199764462377965,
 0.7249353772829186,
 2.1282981021308025,
 0.5118845432809539,
 -1.7654991010243448,
 -0.21305527284688844,
 -0.923057587686486,
 0.39631023834166634,
 -0.1647636107385597,
 -0.6221192458563138,
 0.49382662255730236,
 -0.5498876338674091,
 -0.9614625809946317,
 -0.31826222140608,
 -2.5326501052820967,
 -0.09164546999151812,
 0.20384538202005473,
 -1.3752908671393336,
 -0.9269316488736594,
 -0.9757506923601069,
 1.935204775216786,
 1.8212176474663329,
 -0.0803272375904919,
 0.014600604448272053,
 -3.3532524982396232,
 -1.52150638446552,
 -2.2199155984221446,
 -0.9982231580886729,
 0.14648988069494095,
 0.5971700161204366,
 -1.5938327769327443,
 -0.7658862620736832,
 0.009281952747577817,
 1.4255904181387287,
 -1.267917088559272,
 -0.39122960608878027,
 0.7588424095555801,
 -2.3369498310945116,
 -2.7102890673550344,
 -0.2477368987818303,
 -0.17650137037893276,
 -0.10911621732929978,
 1.3283789350310709,
 -0.45227275924384625,
 1.2423927232704786,
 -0.06114627216058,
 -0.3646701241953688,
 -0.646471008991084,
 1.764950334868243,
 0.6900603414188125,
 -0.49467030073422924,
 -0.28003434138209193,
 -1.8386288159178787,
 -1.2618136088554817,
 1.9010710209398682,
 -1.4314540669769014,
 -0.7570650430493671,
 0.05513263604141096,
 0.237757616256418,
 -0.1474717380959385,
 -0.05619350944350431,
 -0.3116132632124139,
 0.4940766617859332,
 2.3396466311733457,
 0.7224610258758054,
 -0.29295992583262614,
 0.09665093504703058,
 0.4851394914250931,
 0.15263218326443379,
 0.5138461725772208,
 0.3799205515515278,
 1.2628970829494897,
 -1.0820080431408439,
 0.3695735617343116,
 -0.4860160650199529,
 -0.1684576006626541,
 0.2446810954402004,
 0.5813148328758437,
 0.471146035961937,
 -0.15133695982391307,
 -0.10547568124678582,
 -0.7816804392225523,
 -1.4029690399462909,
 1.0048434980808454,
 0.04607444960636761,
 0.5304712563548226,
 -0.7218886536432947,
 0.2088237662834789,
 -1.3869784836185663,
 -0.19858624995564306,
 0.4856045470430043,
 -0.25599481353418563,
 -0.3677314836541136,
 -0.05465736072737579,
 -0.1281147695883516,
 -0.7531497276570971,
 -0.47253658847629215,
 -0.8758830254434338,
 2.2556472538955257,
 -0.5348444650504688,
 -1.9507572498572094,
 1.1284682310164085,
 -0.2670886027808299,
 -0.17911535993921288,
 0.5042949821162876,
 -0.7147407626883117,
 -0.24651693682874032,
 0.8383288363229295,
 0.15568525357799393,
 -1.0674005716628476,
 0.3627608580265455,
 1.4098149629596366,
 1.3293028894679262,
 0.9418334792017098,
 -0.6979116904571373,
 -2.2845841017904873,
 -0.5149040009335427,
 0.6808741263437703,
 0.7484827504795204,
 ...]

从群体中的随机抽样

简单随机抽样有以下特性:

  • 从已知 N 人口单位列表开始,从列表中随机选则 n 个单位
  • 每个单位的选择概率相等,为 n / N
  • 所有可能的 n 大小的样本都是等价的
  • 基于简单随机抽样的平均数、比例和总和的估计都是无偏的,等于平均人口值
In [10]:
import random
import numpy as np
In [11]:
mu = 0
sigma = 1
population = [random.normalvariate(mu, sigma) for _ in range(10000)]
In [12]:
sampleA = random.sample(population, 500)
sampleB = random.sample(population, 500)
In [13]:
np.mean(sampleA)
Out[13]:
0.018759777609701274
In [14]:
np.std(sampleA)
Out[14]:
1.046781958708186
In [15]:
np.mean(sampleB)
Out[15]:
0.018944608887296637
In [16]:
np.std(sampleB)
Out[16]:
0.9889810065807352
In [17]:
means = [np.mean(random.sample(population, 1000)) for _ in range(100)]
np.mean(means)
Out[17]:
0.0037588507984273644
In [21]:
standarddevs = np.std(means)
standarddevs
Out[21]:
0.026175768736385878
In [ ]: