|
| 21 May 2012 10:28 AM |
I have heard of the middle square method.
But how effective is the middle square method?
Are there any other methods out there? |
|
|
| Report Abuse |
|
|
su8
|
  |
| Joined: 06 Mar 2009 |
| Total Posts: 6334 |
|
|
| 21 May 2012 10:29 AM |
| Every random number generator is pseudo-random... |
|
|
| Report Abuse |
|
|
su8
|
  |
| Joined: 06 Mar 2009 |
| Total Posts: 6334 |
|
| |
|
|
| 21 May 2012 10:31 AM |
| Any other methods besides middle square? |
|
|
| Report Abuse |
|
|
|
| 21 May 2012 10:35 AM |
| I understand that part. Dealing with a perfectly logical machine attempting to generate random numbers sounds kinda strange. Thats why its called PseudoRandom |
|
|
| Report Abuse |
|
|
stravant
|
  |
 |
| Joined: 22 Oct 2007 |
| Total Posts: 2893 |
|
|
| 21 May 2012 10:37 AM |
The `Mersenne twister` is the all around best generator out there. It's both easy to implement and generates random numbers good enough for any common use.
It's hard to implement it in a language like Lua which has no low level binary operations, but even taking that into consideration it's probably the best one that you can implement.
Even math.random is probably calling down to Mersenne twister in the end. |
|
|
| Report Abuse |
|
|
|
| 21 May 2012 11:15 AM |
I use my own PRNG with my procedurally-generated terrain (so I can seed it). Here's how it works:
c = CONSTANT b = CONSTANT//Choose a prime number or at least something with no shared multiples with c
a = seed%c OR math.random(1,c)
function rand() a = (a*b)%c return a/c end
And from there you can derive other stuff. It's really simple, but works for most things you'd want to randomly generate.
|
|
|
| Report Abuse |
|
|
|
| 21 May 2012 11:17 AM |
| Cant you seed the roblox one too? |
|
|
| Report Abuse |
|
|
Quenty
|
  |
| Joined: 03 Sep 2009 |
| Total Posts: 9316 |
|
|
| 21 May 2012 11:20 AM |
math.randomseed(354)
:D
Works just as well. |
|
|
| Report Abuse |
|
|
mustyoshi
|
  |
 |
| Joined: 27 Dec 2007 |
| Total Posts: 41651 |
|
|
| 21 May 2012 11:28 AM |
game.Players.PlayerJoined:connect(function(player)math.randomseed(player.userId);end);
Pretty random yo.
~Monica |
|
|
| Report Abuse |
|
|
|
| 21 May 2012 11:31 AM |
@mustyoshi
You could use tick() as well. User ID isn't a bad idea though. |
|
|
| Report Abuse |
|
|
su8
|
  |
| Joined: 06 Mar 2009 |
| Total Posts: 6334 |
|
| |
|
|
| 21 May 2012 11:57 AM |
@su8
The place's ID is constant, so that's useless. As for multiplying tick() and the userId, that's useless too.
All you need is _ONE_ value that will not be the same every time. Multiplying it and stuff is useless, really.
You can also call the math.random function a certain random number of times. |
|
|
| Report Abuse |
|
|
|
| 21 May 2012 05:47 PM |
The Mersenne Twister is not cryptographically secure, so it's NOT the "all around best" generator.
Modifying the middle square slightly to add constants or whatnot improves its issues greatly, by the way, if you still want to pursue that for some reason. |
|
|
| Report Abuse |
|
|
| |
|
|
| 22 May 2012 06:20 AM |
1.make random number, combine with time or watever 2.SHA-512 #1 3.XOR #1 and #2 4.Extract random number |
|
|
| Report Abuse |
|
|
myrkos
|
  |
| Joined: 06 Sep 2010 |
| Total Posts: 8072 |
|
|
| 22 May 2012 09:27 AM |
| arc4random_uniform() is ftw. |
|
|
| Report Abuse |
|
|
|
| 22 May 2012 06:06 PM |
math.randomseed(math.random())
:D |
|
|
| Report Abuse |
|
|
|
| 22 May 2012 06:40 PM |
Issues:
For a generator of n-digit numbers, the period can be no longer than 8n. If the middle 4 digits are all zeroes, the generator then outputs zeroes forever. If the first half of a number in the sequence is zeroes, the subsequent numbers will be decreasing to zero. The middle-squared method can also get stuck on a number other than zero. For n=4, this occurs with the values 0100, 2500, 3792, and 7600. Other seed values form very short repeating cycles, e.g., 0540-2916-5030-3009. These phenomena are even more obvious when n=2, as none of the 100 possible seeds generates more than 14 iterations without reverting to 0, 10, 60, or a 24-57 loop.
(From Wikipedia)
The other problem is the possibility that they will become all zero, which is inescapable. |
|
|
| Report Abuse |
|
|