| 1. |
Solve : Random number generation. How easy?? |
|
Answer» Random number generation. So, please, is there a simple little trick to making a small set of pseudo random numbers? That is like asking if there is a simple little trick to understanding quantum mechanics or particle physics. Quote from: BC_Programmer on June 19, 2011, 05:50:48 PM That is like asking if there is a simple little trick to understanding quantum mechanics or particle physics.Well.. how about just a simple bit of particle physics. How could I do RNG with particle physics.? Does that mean a pair of dice? Here's one way: http://spreadsheets.about.com/b/2009/09/23/random-numbers-in-excel-2007.htm A lot more from GOOGLE here: http://www.google.com/search?client=opera&rls=en&q=random+number+generator&sourceid=opera&ie=utf-8&oe=utf-8&channel=suggestTanks for the link. I made a set and saved it in a text fie. Now I can just use it when I need s set of random numbers.Quote from: Geek-9pm on June 19, 2011, 06:48:52 PM Tanks for the link. I made a set and saved it in a text fie. Now I can just use it when I need s set of random numbers. why did you ask for this: Quote just the outline of a simple algorithm using some constants, addition, subtraction thin gs like that. Yeah, and modulus is OK.if it is clearly not what you needed?I would have like a algorithm. Failing that, just copy a table from a generator and use the table as a base for other sequences. An algorithm like this: X=((A*X)+B))mod C (given x has an initial value >0) depends on the constant A, B and C and the results vary widely So I gave up. What would you do? Quote from: Geek-9pm on June 20, 2011, 03:13:38 AM I would have like a algorithm. Failing that, just copy a table from a generator and use the table as a base for other sequences.You have to choose proper values for the constants for that to work properly, as illustrated in "Art of Computer Programming". The Assembly that is used in the book to illustrate the algorithm: Code: [Select] .DATA align 4 random_32 label dword dd 0ffffffffh ; any seed except 0 .CODE random proc push edx mov eax,[random_32] mov edx,0019660Dh mul edx add eax,3C6EF35Fh mov [random_32],eax pop edx ret random endp The book itself describes why the two specific constant values were chosen(a=19660Dh, c=3C6EF35Fh and M is 2^32) for the formula RND(n+1) = (a*RND(n) + c) mod M). This generates a 32-bit random number; if you want a 8-bit value you take the lower 8 bits, for a random 16-bit value, the lower 16-bits. (the lower bits have more entropy than the upper bits for reasons the book also explains). Quote What would you do?I would simply use the established Random number generator in whatever language I was using, seeded with the SYSTEM Timer, or, and if it's a game, salt that value with some data that is specific to user input, like the amount of time between button presses or something. GETTING an entropic seed is the tough issue, once you have a random number generator that doesn't fall into a sequence.Yes! It is all about the constants to start with! Thanks BC. That will keep me busy. Where did you get that book? Who wrote it? Is it a current work?Quote from: Geek-9pm on June 20, 2011, 03:48:14 AM Where did you get that book?I forget. I think it was given to me, I got a lot of old computer books from my high school Computer Science teacher years ago. Quote Who wrote it?Donald Knuth Quote Is it a current work? if you mean is it recent, well, yes and no; no in that it started in 1962, and yes in that he is still working on it.On Amazon, third edition, hard cover, three volumes, boxed set, about $150, new, in print. Art of Computer Programming, The, Volumes 1-3 Boxed Set (3rd Edition) (Vol 1-3) [Hardcover] |
|