generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Pseudo-random number generation

Previous Thread :: Next Thread 
Kaboose671 is not online. Kaboose671
Joined: 12 Jun 2010
Total Posts: 20500
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 is not online. su8
Joined: 06 Mar 2009
Total Posts: 6334
21 May 2012 10:29 AM
Every random number generator is pseudo-random...
Report Abuse
su8 is not online. su8
Joined: 06 Mar 2009
Total Posts: 6334
21 May 2012 10:30 AM
cuz u cant do real random
Report Abuse
Kaboose671 is not online. Kaboose671
Joined: 12 Jun 2010
Total Posts: 20500
21 May 2012 10:31 AM
Any other methods besides middle square?
Report Abuse
Kaboose671 is not online. Kaboose671
Joined: 12 Jun 2010
Total Posts: 20500
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 is not online. stravant
Forum Moderator
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
PurpleKiwi is not online. PurpleKiwi
Joined: 26 Jul 2008
Total Posts: 4022
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
Radioaktiivinen is not online. Radioaktiivinen
Joined: 25 Apr 2009
Total Posts: 18629
21 May 2012 11:17 AM
Cant you seed the roblox one too?
Report Abuse
Quenty is not online. 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 is not online. mustyoshi
Top 50 Poster
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
Nytraulics is not online. Nytraulics
Joined: 29 Jul 2011
Total Posts: 755
21 May 2012 11:31 AM
@mustyoshi

You could use tick() as well. User ID isn't a bad idea though.
Report Abuse
su8 is not online. su8
Joined: 06 Mar 2009
Total Posts: 6334
21 May 2012 11:34 AM
tick()*userId/placeId
Report Abuse
JulienDethurens is not online. JulienDethurens
Joined: 11 Jun 2009
Total Posts: 11046
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
BlueTaslem is not online. BlueTaslem
Joined: 11 May 2008
Total Posts: 11060
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
Kaboose671 is not online. Kaboose671
Joined: 12 Jun 2010
Total Posts: 20500
21 May 2012 09:43 PM
Issues?
Report Abuse
Radioaktiivinen is not online. Radioaktiivinen
Joined: 25 Apr 2009
Total Posts: 18629
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 is not online. myrkos
Joined: 06 Sep 2010
Total Posts: 8072
22 May 2012 09:27 AM
arc4random_uniform() is ftw.
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
22 May 2012 06:06 PM
math.randomseed(math.random())

:D
Report Abuse
BlueTaslem is not online. BlueTaslem
Joined: 11 May 2008
Total Posts: 11060
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image