Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Last revision Both sides next revision
cs-312:randombigintegers [2015/01/31 11:47]
cs312ta
cs-312:randombigintegers [2015/01/31 11:56]
cs312ta
Line 37: Line 37:
 <​pre>​random_number %= N;</​pre>​ <​pre>​random_number %= N;</​pre>​
 This however can create uneven distributions if N and the largest value of random_number are similar ((http://​jsfiddle.net/​trevordixon/​ZvquF/​5/​)) This however can create uneven distributions if N and the largest value of random_number are similar ((http://​jsfiddle.net/​trevordixon/​ZvquF/​5/​))
- +== Interactive Visualization / Example in C# == 
-== Alternative Approach ​#2 - retry until number is less than N == +We have made program that has both methods of generating BigIntegers ​and draws the distribution of the randomly generated numbersIn the program you can select "​mod"​ to see BigIntegers generated by simply modding, and then by selecting "​repeat"​ you will see the distribution when the random ​code is repeated until a number ​in the desired range is obtained. It also shows you the time required to generate all the numbers so you can get sense for the difference in performance. 
-Put your code to generate the random BigInteger in loop and continue ​generating ​random ​BigIntegers ​until the random BigInteger is less than N. +{{:​cs-312:​randombigintegers.zip|}}
-<​code>​ +
-BigInteger random_number = CreateRandomBigInteger(N);​ +
-while (N > random_number) { +
-    random_number = CreateRandomBigInteger(N);​ +
-+
-</​code>​ +
-This will ensure that your random number ​distribution ​is even but could take a very long time with this code if N is 33 bit integer.+
cs-312/randombigintegers.txt · Last modified: 2015/01/31 11:59 by cs312ta
Back to top
CC Attribution-Share Alike 4.0 International
chimeric.de = chi`s home Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0