• ### What is your GameDev Story?

#### Archived

This topic is now archived and is closed to further replies.

# RNG Entropy?

This topic is 5367 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I build my first RNG program today One uses the get QueryPerformanceFrequency, QueryPerformanceCounter and Gettickcount to find the difference. the code is like this,
QueryPerformanceFrequency curFreq ''Get the timer frequency
QueryPerformanceCounter curStart ''Get the start time
ctime = curStart / curFreq
k = GetTickCount / 1000
cdiff = Abs(k - ctime)
cdiff = cdiff * 1000

For the non-VB coders, ABS returns absolute positive numbers, like abs(-100) would return 100. i then remove the decimal point in cdiff, do some anti-mod-overloadcode then mod it with 2, to get each bit. I tested it using this http://www.fourmilab.ch/random/ And found the entropy to be 7.975742 bits per byte. I''ll post the extra information (extra statistics) once i finish my empirical study (i''m getting it to generate ten million random numbers, so i can find weaknesses). is 7.9 entropy bits per byte good? is my method of getting entropy good? Should i instead use hashes (maybe SHA-1 32767 bytes to get a 160 bit hash, what would happen?)?

##### Share on other sites
Test are in, in 10 million bytes of random data results were:
(sory for the wait... please post! - from someone who is lonely)
Value Char Occurrences Fraction  0            10233   0.001023  1            16892   0.001689  2            10702   0.001070  3            29508   0.002951  4            24078   0.002408  5            20931   0.002093  6            59368   0.005937  7            92877   0.009288  8            21741   0.002174  9            23727   0.002373 10            24584   0.002458 11            25076   0.002508 12           185833   0.018583 13            46966   0.004697 14           388889   0.038889 15           103821   0.010382 16            16366   0.001637 17            19750   0.001975 18            26965   0.002696 19            22606   0.002261 20            25279   0.002528 21            13617   0.001362 22            24684   0.002468 23            16771   0.001677 24           176597   0.017660 25            38661   0.003866 26            35345   0.003534 27            37016   0.003702 28           244716   0.024472 29            32557   0.003256 30            71130   0.007113 31            29198   0.002920 32            13456   0.001346 33   !        23042   0.002304 34   "        17115   0.001711 35   #        38103   0.003810 36   $63850 0.006385 37 % 37417 0.003742 38 & 46705 0.004670 39 '' 40656 0.004066 40 ( 12939 0.001294 41 ) 18273 0.001827 42 * 14142 0.001414 43 + 15496 0.001550 44 , 36100 0.003610 45 - 38339 0.003834 46 . 29510 0.002951 47 / 17238 0.001724 48 0 23142 0.002314 49 1 45519 0.004552 50 2 44909 0.004491 51 3 32608 0.003261 52 4 23494 0.002349 53 5 16761 0.001676 54 6 44606 0.004461 55 7 14384 0.001438 56 8 89600 0.008960 57 9 44736 0.004474 58 : 21112 0.002111 59 ; 19154 0.001915 60 < 39783 0.003978 61 = 16603 0.001660 62 > 19304 0.001930 63 ? 11238 0.001124 64 @ 13297 0.001330 65 A 22137 0.002214 66 B 18585 0.001858 67 C 46730 0.004673 68 D 24341 0.002434 69 E 27736 0.002774 70 F 76627 0.007663 71 G 190154 0.019015 72 H 16054 0.001605 73 I 44728 0.004473 74 J 20017 0.002002 75 K 25301 0.002530 76 L 36920 0.003692 77 M 49093 0.004909 78 N 67955 0.006795 79 O 34471 0.003447 80 P 13726 0.001373 81 Q 20252 0.002025 82 R 39612 0.003961 83 S 30351 0.003035 84 T 17319 0.001732 85 U 14818 0.001482 86 V 21635 0.002163 87 W 14857 0.001486 88 X 34140 0.003414 89 Y 44280 0.004428 90 Z 37478 0.003748 91 [ 62958 0.006296 92 \ 38006 0.003801 93 ] 18200 0.001820 94 ^ 25002 0.002500 95 _ 14582 0.001458 96  19723 0.001972 97 a 46117 0.004612 98 b 23121 0.002312 99 c 148784 0.014878100 d 32994 0.003299101 e 33514 0.003351102 f 37213 0.003721103 g 174350 0.017435104 h 11209 0.001121105 i 18678 0.001868106 j 11386 0.001139107 k 19269 0.001927108 l 20716 0.002072109 m 28350 0.002835110 n 18452 0.001845111 o 17038 0.001704112 p 34067 0.003407113 q 119777 0.011978114 r 31021 0.003102115 s 77583 0.007758116 t 15167 0.001517117 u 15580 0.001558118 v 19865 0.001986119 w 13754 0.001375120 x 39359 0.003936121 y 26775 0.002677122 z 14995 0.001499123 { 15950 0.001595124 | 16982 0.001698125 } 8632 0.000863126 ~ 11583 0.001158127 7302 0.000730128 7131 0.000713129 11021 0.001102130 8522 0.000852131 16115 0.001611132 15414 0.001541133 15011 0.001501134 25710 0.002571135 37815 0.003781136 13669 0.001367137 19845 0.001984138 15335 0.001533139 14928 0.001493140 74998 0.007500141 30327 0.003033142 114151 0.011415143 33819 0.003382144 16379 0.001638145 17225 0.001722146 27798 0.002780147 19948 0.001995148 18444 0.001844149 10951 0.001095150 18039 0.001804151 10886 0.001089152 163099 0.016310153 36219 0.003622154 32724 0.003272155 33135 0.003313156 140759 0.014076157 22592 0.002259158 44243 0.004424159 19494 0.001949160 13997 0.001400161 ¡ 23955 0.002395162 ¢ 17681 0.001768163 £ 35102 0.003510164 ¤ 61443 0.006144165 ¥ 36867 0.003687166 ¦ 43800 0.004380167 § 32853 0.003285168 ¨ 14299 0.001430169 © 20636 0.002064170 ª 14281 0.001428171 « 16908 0.001691172 ¬ 29209 0.002921173 ­ 38359 0.003836174 ® 20092 0.002009175 ¯ 13301 0.001330176 ° 32026 0.003203177 ± 61485 0.006148178 ² 47841 0.004784179 ³ 35060 0.003506180 ´ 24258 0.002426181 µ 19095 0.001909182 ¶ 43718 0.004372183 · 15400 0.001540184 ¸ 176337 0.017634185 ¹ 70004 0.007000186 º 26663 0.002666187 » 23652 0.002365188 ¼ 44300 0.004430189 ½ 17938 0.001794190 ¾ 22036 0.002204191 ¿ 13141 0.001314192 À 10151 0.001015193 Á 17616 0.001762194 Â 15737 0.001574195 Ã 36992 0.003699196 Ä 18348 0.001835197 Å 20322 0.002032198 Æ 42980 0.004298199 Ç 85317 0.008532200 È 13819 0.001382201 É 44474 0.004447202 Ê 16906 0.001691203 Ë 23599 0.002360204 Ì 31517 0.003152205 Í 44697 0.004470206 Î 44483 0.004448207 Ï 22882 0.002288208 Ð 16623 0.001662209 Ñ 27418 0.002742210 Ò 37486 0.003749211 Ó 34316 0.003432212 Ô 15007 0.001501213 Õ 13823 0.001382214 Ö 17322 0.001732215 × 12169 0.001217216 Ø 37733 0.003773217 Ù 45880 0.004588218 Ú 36440 0.003644219 Û 62426 0.006243220 Ü 35770 0.003577221 Ý 17298 0.001730222 Þ 22497 0.002250223 ß 13382 0.001338224 à 24834 0.002483225 á 62393 0.006239226 â 28787 0.002879227 ã 209053 0.020905228 ä 35214 0.003521229 å 33815 0.003381230 æ 36338 0.003634231 ç 159866 0.015987232 è 15028 0.001503233 é 23214 0.002321234 ê 12889 0.001289235 ë 22810 0.002281236 ì 21356 0.002136237 í 26337 0.002634238 î 18743 0.001874239 ï 15717 0.001572240 ð 91585 0.009158241 ñ 333050 0.033305242 ò 42908 0.004291243 ó 153282 0.015328244 ô 23091 0.002309245 õ 22313 0.002231246 ö 22854 0.002285247 ÷ 19778 0.001978248 ø 82922 0.008292249 ù 53568 0.005357250 ú 20199 0.002020251 û 22048 0.002205252 ü 27080 0.002708253 ý 10262 0.001026254 þ 15711 0.001571255 ÿ 9569 0.000957Total: 10000013 1.000000Entropy = 7.414464 bits per byte.Optimum compression would reduce the sizeof this 10000013 byte file by 7 percent.Chi square distribution for 10000013 samples is 14211210.01, and randomlywould exceed this value 0.01 percent of the times.Arithmetic mean value of data bytes is 124.4440 (127.5 = random).Monte Carlo value for Pi is 3.141098287 (error 0.02 percent).Serial correlation coefficient is -0.072072 (totally uncorrelated = 0.0).Value Char Occurrences Fraction 0 10233 0.001023 1 16892 0.001689 2 10702 0.001070 3 29508 0.002951 4 24078 0.002408 5 20931 0.002093 6 59368 0.005937 7 92877 0.009288 8 21741 0.002174 9 23727 0.002373 10 24584 0.002458 11 25076 0.002508 12 185833 0.018583 13 46966 0.004697 14 388889 0.038889 15 103821 0.010382 16 16366 0.001637 17 19750 0.001975 18 26965 0.002696 19 22606 0.002261 20 25279 0.002528 21 13617 0.001362 22 24684 0.002468 23 16771 0.001677 24 176597 0.017660 25 38661 0.003866 26 35345 0.003534 27 37016 0.003702 28 244716 0.024472 29 32557 0.003256 30 71130 0.007113 31 29198 0.002920 32 13456 0.001346 33 ! 23042 0.002304 34 " 17115 0.001711 35 # 38103 0.003810 36$        63850   0.006385 37   %        37417   0.003742 38   &        46705   0.004670 39   ''        40656   0.004066 40   (        12939   0.001294 41   )        18273   0.001827 42   *        14142   0.001414 43   +        15496   0.001550 44   ,        36100   0.003610 45   -        38339   0.003834 46   .        29510   0.002951 47   /        17238   0.001724 48   0        23142   0.002314 49   1        45519   0.004552 50   2        44909   0.004491 51   3        32608   0.003261 52   4        23494   0.002349 53   5        16761   0.001676 54   6        44606   0.004461 55   7        14384   0.001438 56   8        89600   0.008960 57   9        44736   0.004474 58   :        21112   0.002111 59   ;        19154   0.001915 60   <        39783   0.003978 61   =        16603   0.001660 62   >        19304   0.001930 63   ?        11238   0.001124 64   @        13297   0.001330 91   [        62958   0.006296 92   \        38006   0.003801 93   ]        18200   0.001820 94   ^        25002   0.002500 95   _        14582   0.001458 96           19723   0.001972 97   a        68254   0.006825 98   b        41706   0.004171 99   c       195514   0.019551100   d        57335   0.005733101   e        61250   0.006125102   f       113840   0.011384103   g       364504   0.036450104   h        27263   0.002726105   i        63406   0.006341106   j        31403   0.003140107   k        44570   0.004457108   l        57636   0.005764109   m        77443   0.007744110   n        86407   0.008641111   o        51509   0.005151112   p        47793   0.004779113   q       140029   0.014003114   r        70633   0.007063115   s       107934   0.010793116   t        32486   0.003249117   u        30398   0.003040118   v        41500   0.004150119   w        28611   0.002861120   x        73499   0.007350121   y        71055   0.007105122   z        52473   0.005247123   {        15950   0.001595124   |        16982   0.001698125   }         8632   0.000863126   ~        11583   0.001158127             7302   0.000730128             7131   0.000713129            11021   0.001102130             8522   0.000852131            16115   0.001611132            15414   0.001541133            15011   0.001501134            25710   0.002571135            37815   0.003781136            13669   0.001367137            19845   0.001984138            15335   0.001533139            14928   0.001493140            74998   0.007500141            30327   0.003033142           114151   0.011415143            33819   0.003382144            16379   0.001638145            17225   0.001722146            27798   0.002780147            19948   0.001995148            18444   0.001844149            10951   0.001095150            18039   0.001804151            10886   0.001089152           163099   0.016310153            36219   0.003622154            32724   0.003272155            33135   0.003313156           140759   0.014076157            22592   0.002259158            44243   0.004424159            19494   0.001949160            13997   0.001400161   ¡        23955   0.002395162   ¢        17681   0.001768163   £        35102   0.003510164   ¤        61443   0.006144165   ¥        36867   0.003687166   ¦        43800   0.004380167   §        32853   0.003285168   ¨        14299   0.001430169   ©        20636   0.002064170   ª        14281   0.001428171   «        16908   0.001691172   ¬        29209   0.002921173   ­        38359   0.003836174   ®        20092   0.002009175   ¯        13301   0.001330176   °        32026   0.003203177   ±        61485   0.006148178   ²        47841   0.004784179   ³        35060   0.003506180   ´        24258   0.002426181   µ        19095   0.001909182   ¶        43718   0.004372183   ·        15400   0.001540184   ¸       176337   0.017634185   ¹        70004   0.007000186   º        26663   0.002666187   »        23652   0.002365188   ¼        44300   0.004430189   ½        17938   0.001794190   ¾        22036   0.002204191   ¿        13141   0.001314215   ×        12169   0.001217223   ß        13382   0.001338224   à        34985   0.003498225   á        80009   0.008001226   â        44524   0.004452227   ã       246045   0.024604228   ä        53562   0.005356229   å        54137   0.005414230   æ        79318   0.007932231   ç       245183   0.024518232   è        28847   0.002885233   é        67688   0.006769234   ê        29795   0.002979235   ë        46409   0.004641236   ì        52873   0.005287237   í        71034   0.007103238   î        63226   0.006323239   ï        38599   0.003860240   ð       108208   0.010821241   ñ       360468   0.036047242   ò        80394   0.008039243   ó       187598   0.018760244   ô        38098   0.003810245   õ        36136   0.003614246   ö        40176   0.004018247   ÷        19778   0.001978248   ø       120655   0.012065249   ù        99448   0.009945250   ú        56639   0.005664251   û        84474   0.008447252   ü        62850   0.006285253   ý        27560   0.002756254   þ        38208   0.003821255   ÿ         9569   0.000957Total:      10000013   1.000000Entropy = 7.024495 bits per byte.Optimum compression would reduce the sizeof this 10000013 byte file by 12 percent.Chi square distribution for 10000013 samples is 20429391.96, and randomlywould exceed this value 0.01 percent of the times.Arithmetic mean value of data bytes is 130.5214 (127.5 = random).Monte Carlo value for Pi is 2.902380078 (error 7.61 percent).Serial correlation coefficient is -0.058784 (totally uncorrelated = 0.0).Entropy = 0.999967 bits per bit.Optimum compression would reduce the sizeof this 80000104 bit file by 0 percent.Chi square distribution for 80000104 samples is 3648.91, and randomlywould exceed this value 0.01 percent of the times.Arithmetic mean value of data bits is 0.4966 (0.5 = random).Monte Carlo value for Pi is 3.141098287 (error 0.02 percent).Serial correlation coefficient is 0.102919 (totally uncorrelated = 0.0).Value Char Occurrences Fraction  0         40270197   0.503377  1         39729907   0.496623Total:      80000104   1.000000Entropy = 0.999967 bits per bit.Optimum compression would reduce the sizeof this 80000104 bit file by 0 percent.Chi square distribution for 80000104 samples is 3648.91, and randomlywould exceed this value 0.01 percent of the times.Arithmetic mean value of data bits is 0.4966 (0.5 = random).Monte Carlo value for Pi is 3.141098287 (error 0.02 percent).Serial correlation coefficient is 0.102919 (totally uncorrelated = 0.0).0,File-bytes,Entropy,Chi-square,Mean,Monte-Carlo-Pi,Serial-Correlation1,10000013,7.414464,14211210.008021,124.443998,3.141098,-0.0720720,File-bytes,Entropy,Chi-square,Mean,Monte-Carlo-Pi,Serial-Correlation1,10000013,7.414464,14211210.008021,124.443998,3.141098,-0.0720722,Value,Occurrences,Fraction3,0,10233,0.0010233,1,16892,0.0016893,2,10702,0.0010703,3,29508,0.0029513,4,24078,0.0024083,5,20931,0.0020933,6,59368,0.0059373,7,92877,0.0092883,8,21741,0.0021743,9,23727,0.0023733,10,24584,0.0024583,11,25076,0.0025083,12,185833,0.0185833,13,46966,0.0046973,14,388889,0.0388893,15,103821,0.0103823,16,16366,0.0016373,17,19750,0.0019753,18,26965,0.0026963,19,22606,0.0022613,20,25279,0.0025283,21,13617,0.0013623,22,24684,0.0024683,23,16771,0.0016773,24,176597,0.0176603,25,38661,0.0038663,26,35345,0.0035343,27,37016,0.0037023,28,244716,0.0244723,29,32557,0.0032563,30,71130,0.0071133,31,29198,0.0029203,32,13456,0.0013463,33,23042,0.0023043,34,17115,0.0017113,35,38103,0.0038103,36,63850,0.0063853,37,37417,0.0037423,38,46705,0.0046703,39,40656,0.0040663,40,12939,0.0012943,41,18273,0.0018273,42,14142,0.0014143,43,15496,0.0015503,44,36100,0.0036103,45,38339,0.0038343,46,29510,0.0029513,47,17238,0.0017243,48,23142,0.0023143,49,45519,0.0045523,50,44909,0.0044913,51,32608,0.0032613,52,23494,0.0023493,53,16761,0.0016763,54,44606,0.0044613,55,14384,0.0014383,56,89600,0.0089603,57,44736,0.0044743,58,21112,0.0021113,59,19154,0.0019153,60,39783,0.0039783,61,16603,0.0016603,62,19304,0.0019303,63,11238,0.0011243,64,13297,0.0013303,65,22137,0.0022143,66,18585,0.0018583,67,46730,0.0046733,68,24341,0.0024343,69,27736,0.0027743,70,76627,0.0076633,71,190154,0.0190153,72,16054,0.0016053,73,44728,0.0044733,74,20017,0.0020023,75,25301,0.0025303,76,36920,0.0036923,77,49093,0.0049093,78,67955,0.0067953,79,34471,0.0034473,80,13726,0.0013733,81,20252,0.0020253,82,39612,0.0039613,83,30351,0.0030353,84,17319,0.0017323,85,14818,0.0014823,86,21635,0.0021633,87,14857,0.0014863,88,34140,0.0034143,89,44280,0.0044283,90,37478,0.0037483,91,62958,0.0062963,92,38006,0.0038013,93,18200,0.0018203,94,25002,0.0025003,95,14582,0.0014583,96,19723,0.0019723,97,46117,0.0046123,98,23121,0.0023123,99,148784,0.0148783,100,32994,0.0032993,101,33514,0.0033513,102,37213,0.0037213,103,174350,0.0174353,104,11209,0.0011213,105,18678,0.0018683,106,11386,0.0011393,107,19269,0.0019273,108,20716,0.0020723,109,28350,0.0028353,110,18452,0.0018453,111,17038,0.0017043,112,34067,0.0034073,113,119777,0.0119783,114,31021,0.0031023,115,77583,0.0077583,116,15167,0.0015173,117,15580,0.0015583,118,19865,0.0019863,119,13754,0.0013753,120,39359,0.0039363,121,26775,0.0026773,122,14995,0.0014993,123,15950,0.0015953,124,16982,0.0016983,125,8632,0.0008633,126,11583,0.0011583,127,7302,0.0007303,128,7131,0.0007133,129,11021,0.0011023,130,8522,0.0008523,131,16115,0.0016113,132,15414,0.0015413,133,15011,0.0015013,134,25710,0.0025713,135,37815,0.0037813,136,13669,0.0013673,137,19845,0.0019843,138,15335,0.0015333,139,14928,0.0014933,140,74998,0.0075003,141,30327,0.0030333,142,114151,0.0114153,143,33819,0.0033823,144,16379,0.0016383,145,17225,0.0017223,146,27798,0.0027803,147,19948,0.0019953,148,18444,0.0018443,149,10951,0.0010953,150,18039,0.0018043,151,10886,0.0010893,152,163099,0.0163103,153,36219,0.0036223,154,32724,0.0032723,155,33135,0.0033133,156,140759,0.0140763,157,22592,0.0022593,158,44243,0.0044243,159,19494,0.0019493,160,13997,0.0014003,161,23955,0.0023953,162,17681,0.0017683,163,35102,0.0035103,164,61443,0.0061443,165,36867,0.0036873,166,43800,0.0043803,167,32853,0.0032853,168,14299,0.0014303,169,20636,0.0020643,170,14281,0.0014283,171,16908,0.0016913,172,29209,0.0029213,173,38359,0.0038363,174,20092,0.0020093,175,13301,0.0013303,176,32026,0.0032033,177,61485,0.0061483,178,47841,0.0047843,179,35060,0.0035063,180,24258,0.0024263,181,19095,0.0019093,182,43718,0.0043723,183,15400,0.0015403,184,176337,0.0176343,185,70004,0.0070003,186,26663,0.0026663,187,23652,0.0023653,188,44300,0.0044303,189,17938,0.0017943,190,22036,0.0022043,191,13141,0.0013143,192,10151,0.0010153,193,17616,0.0017623,194,15737,0.0015743,195,36992,0.0036993,196,18348,0.0018353,197,20322,0.0020323,198,42980,0.0042983,199,85317,0.0085323,200,13819,0.0013823,201,44474,0.0044473,202,16906,0.0016913,203,23599,0.0023603,204,31517,0.0031523,205,44697,0.0044703,206,44483,0.0044483,207,22882,0.0022883,208,16623,0.0016623,209,27418,0.0027423,210,37486,0.0037493,211,34316,0.0034323,212,15007,0.0015013,213,13823,0.0013823,214,17322,0.0017323,215,12169,0.0012173,216,37733,0.0037733,217,45880,0.0045883,218,36440,0.0036443,219,62426,0.0062433,220,35770,0.0035773,221,17298,0.0017303,222,22497,0.0022503,223,13382,0.0013383,224,24834,0.0024833,225,62393,0.0062393,226,28787,0.0028793,227,209053,0.0209053,228,35214,0.0035213,229,33815,0.0033813,230,36338,0.0036343,231,159866,0.0159873,232,15028,0.0015033,233,23214,0.0023213,234,12889,0.0012893,235,22810,0.0022813,236,21356,0.0021363,237,26337,0.0026343,238,18743,0.0018743,239,15717,0.0015723,240,91585,0.0091583,241,333050,0.0333053,242,42908,0.0042913,243,153282,0.0153283,244,23091,0.0023093,245,22313,0.0022313,246,22854,0.0022853,247,19778,0.0019783,248,82922,0.0082923,249,53568,0.0053573,250,20199,0.0020203,251,22048,0.0022053,252,27080,0.0027083,253,10262,0.0010263,254,15711,0.0015713,255,9569,0.0009570,File-bytes,Entropy,Chi-square,Mean,Monte-Carlo-Pi,Serial-Correlation1,10000013,7.024495,20429391.964039,130.521417,2.902380,-0.0587840,File-bits,Entropy,Chi-square,Mean,Monte-Carlo-Pi,Serial-Correlation1,80000104,0.999967,3648.911308,0.496623,3.141098,0.1029190,File-bits,Entropy,Chi-square,Mean,Monte-Carlo-Pi,Serial-Correlation1,80000104,0.999967,3648.911308,0.496623,3.141098,0.1029192,Value,Occurrences,Fraction3,0,40270197,0.5033773,1,39729907,0.496623

##### Share on other sites
You left out a lot of code.

I don't understand why you use GetTickCount. It seems to me that if you modify your method by removing the GetTickCount part and just use the raw value from QueryPerformanceCounter, you would get the same (or better) results.

Some observations (though I'm not sure of the statistical significance):

The distribution does not seem very uniform. The average per character should around 39,000 but most are much smaller except a few that are much much larger.

Also, notice that the means are 130.5214 and 124.4440. With 10,000,000 samples, I would expect the means to be very very close to 127.5. This is probably related to the lumpy distribution.

John Bolton
Page 44 Studios
Current project: NHL Faceoff 2005 PS2

[edited by - JohnBolton on May 8, 2004 2:50:03 PM]

##### Share on other sites
I used Gettickcount because it sometimes Lags ahead/behind Queryperformancecounter. (from my tests, not much, but its enough.)

The way i got my bits is by taking
do until cdiff < 32767 'make sure mod doesn't overloadcdiff = cdiff / 255doeventslooprbit = cdiff mod 2I then stack the rbits to build 8-bit bytesThen use a binary-decimal converter to convert them into bytesthen i pack them into the file.

Is this a good way to produce the bits?
This is my first (psudo-ish) Random number Generator! (is it an OK first attempt?)
And Can i improve entropy/randomness by putting a few KB of my random number generator into a Hash algarithm? (I just happen to have an MD5 DLL hanging around).

Should i add a wait inbetween collection of bits?
doQueryperformantscounter curstartGettickcountget bitadd bit to byteloop

It would be
dowait n msQueryperformantscounterGettickcountGet bitadd bit to byteloop

?
Thank you for posting (this is my third thread, about my 100dreth post).
*edit-still getting used to the source tags*
DE NC

[edited by - Nice coder on May 8, 2004 9:24:42 PM]

##### Share on other sites
I really think that using GetTickCount is reducing the randomness. Here''s why.

On my system, GetTickCount updates 60 times per second and the frequency of QueryPerformanceCounter is 3.58 MHz. The timing of these two counters is extremely precise (and probably based on the same timer), so hoping to gain randomness due to timing fluctuation is not realistic. Assuming that GTC and QPC are synchronized every 1/60th of a second, your random value is simply the number of QPC ticks in the last 1/60th of a second. The range of that value is 0 to 59500 (3,570,000/60) and that is only 16 bits.

If you use QPC by itself, the counter will count (at 3.58 MHz) through the bottom 24 bits every 5 seconds and the bottom 32 bits every 20 minutes.

Why even bother with GetTickCount?

##### Share on other sites
Thank you for the info (im going to fix that soon).

Would i use
Queryperformantscounter curstart
Then convert it to binary.
Then use the number of 1''s % 2 to find the random bit?
Would this be more randomish?
Should i hash this data?

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 17
• 14
• 10
• 9
• 11
• ### Forum Statistics

• Total Topics
634097
• Total Posts
3015505
×