# 与其想当然的 overdesign，不如自己动手做个试验

Conmajia
Jan. 29th, 2019

## 已经足够好的 Random

Case #1 的数据，是用默认构造函数初始化生成的数据统计概率直方图$x$ 轴是输出的随机数数值，范围从0-99，共100个数。$y$ 轴是对应数值出现的概率。每次试验生成 10,000,000（一千万）个随机数，每个case进行10次试验，共生成100,000,000（一亿）个随机数，得到单次试验平均用时0.76秒。令 $\tau=0.76$，后面的case都按类似的方法进行，并以 $\tau$ 作为性能基准，排除计算平台的干扰。

Case #1new Random()，用时：$\tau=0.76$

Case #2new Random(GUID)，用时：$52\tau$

Case #3new Random(GUID * Time * count)，用时：$56\tau$

## 您可省省吧！

The End. $\Box$

 function paintCanvas(canvas,data,title=''){var chart=echarts.init(document.getElementById(canvas));chart.setOption({title:{text:title},tooltip:{},legend:{data:['']},dataZoom:[{id:'dataZoomX',type:'slider',xAxisIndex:[0],filterMode:'filter'}],xAxis:{type:'category',data:data.x},yAxis:{scale:true},series:[{name:'',type:'bar',data:data.y}],grid:{top:10}})} paintCanvas('canvas-uniform',{x:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99],y:[0.009999,0.0099791,0.0099851,0.010045,0.0099323,0.0100227,0.009973,0.0099823,0.0099812,0.0100117,0.0099555,0.0100219,0.0099808,0.0099235,0.0100256,0.0100195,0.0100347,0.0099649,0.0099957,0.0100012,0.0099983,0.0100443,0.0100185,0.0100028,0.0099762,0.0099998,0.010038,0.0099765,0.0100109,0.01005,0.01003,0.0100054,0.0099526,0.010001,0.0100172,0.0100067,0.0099779,0.0100547,0.0100519,0.009982,0.0100288,0.0100559,0.0100406,0.0099738,0.009963,0.0099715,0.0099753,0.0099745,0.0099862,0.0099928,0.0100211,0.009992,0.0100048,0.0099731,0.0100005,0.0100157,0.0100208,0.0099976,0.0099595,0.01004,0.0100246,0.0100253,0.0100169,0.0099769,0.0099607,0.0100206,0.010013,0.0099873,0.0099567,0.0099987,0.0099625,0.0100595,0.0099338,0.0100009,0.0100181,0.0099867,0.0100141,0.010015,0.0099953,0.0100089,0.0100287,0.0100257,0.0100045,0.0100001,0.0100012,0.0100357,0.0099458,0.0100448,0.0099926,0.0099496,0.0100401,0.0099849,0.0099666,0.0100041,0.0100289,0.0099873,0.009978,0.0099922,0.0099923,0.0100045]}); paintCanvas('canvas-guid-complex',{x:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99],y:[0.0099588,0.0099963,0.0099867,0.0100279,0.0099967,0.010009,0.0100268,0.0099682,0.0100487,0.0099889,0.0099977,0.0100182,0.0099335,0.0100526,0.009973,0.0100066,0.0100051,0.0100047,0.0099966,0.0099876,0.0100194,0.0099806,0.0100175,0.0099505,0.0100212,0.0100264,0.009992,0.0100031,0.009983,0.010008,0.0099936,0.0099991,0.0099872,0.0100077,0.0099912,0.010037,0.0099905,0.010021,0.009914,0.0100222,0.0100325,0.0100102,0.0099669,0.0100526,0.0100275,0.0099605,0.009992,0.0100189,0.009977,0.0099784,0.0100042,0.0100493,0.0100071,0.0100028,0.0099897,0.0099899,0.0100025,0.0100122,0.0099531,0.0099807,0.0099904,0.0100486,0.0099704,0.0100065,0.010033,0.0100121,0.0099809,0.0100112,0.0099883,0.0100166,0.0100253,0.0100342,0.0100222,0.0099733,0.010014,0.0100402,0.0100118,0.0099748,0.0099949,0.0099435,0.0100269,0.0100096,0.0100035,0.0099935,0.0100527,0.010029,0.0099903,0.0100189,0.0099248,0.0099613,0.0100053,0.010031,0.0099276,0.0099528,0.0100068,0.0099687,0.0100655,0.0100228,0.0099488,0.0100112]}); paintCanvas('canvas-guid',{x:[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99],y:[0.009969,0.0099814,0.010007,0.0099734,0.0100348,0.0099411,0.010003,0.0099791,0.0100223,0.0100081,0.010043,0.0099691,0.0100782,0.0099857,0.0100318,0.0099852,0.0099031,0.0100022,0.0099955,0.0100051,0.0100461,0.0100305,0.0099732,0.010001,0.0100225,0.0099725,0.0099751,0.0099508,0.0100818,0.0100174,0.0099828,0.0099956,0.0100132,0.0099434,0.0100041,0.0100116,0.0100056,0.0099988,0.0099917,0.0099825,0.0100184,0.0100239,0.0100129,0.010003,0.0099602,0.0099697,0.0100037,0.0100334,0.0099445,0.0099953,0.0100062,0.0100498,0.0099619,0.0100386,0.0100099,0.0099716,0.009962,0.009943,0.010002,0.0100403,0.0100361,0.0099616,0.0100443,0.0100754,0.0099895,0.0100405,0.0100066,0.0100115,0.0099725,0.0100516,0.0099657,0.0099764,0.0100091,0.0100129,0.0100226,0.0099746,0.009995,0.0100378,0.0099761,0.010022,0.0099874,0.0099882,0.0099836,0.0100138,0.0100195,0.0100456,0.0099339,0.0099185,0.0099723,0.0099984,0.0100329,0.010027,0.0099859,0.0100038,0.0099408,0.0100047,0.0100058,0.0100318,0.010004,0.0100517]}); 
1. 所有的真随机数发生器都需要专用硬件支持，它们中绝大部分受到发明专利保护。System.Random 基于 Donald E. Knuth 的减随机数生成器算法实现，从实用角度而言，随机程度已经足够。 ↩︎

posted @ 2019-01-30 09:11  Conmajia  阅读(1188)  评论(7编辑  收藏  举报