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 » Scripting Helpers
Home Search
 

Re: Pseudo-Random Number Generator

Previous Thread :: Next Thread 
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
12 Jun 2012 10:00 PM
Currently I have one that uses LCG, but there's a few problems:

 - I don't know how to add an effective minimum to Random
 - It sometimes has a short period (i.e. it goes 4,3,2,1,4,3,2,1,4,3,2 when you do Random(4))
 - It sometimes repeats (i.e. 3,3,3,3,3,3,3,3,3)

    local Cur = 0
    local Results = {}
    function SetSeed(seed)
        Results = {[0] = math.floor(seed)}
        for i = 0, 100 do
            Results[i + 1] = (1.3.4.7.7.5.8.1.3 * Results[i] + 1) % 4.2.9.4.9.6.7.2.9.6 //ignore the .s, dumb filter
        end
    end
    function Random(Max)
        Cur = Cur + 1
        return (Results[Cur] % Max) + 1
    end

Any ways to make it better?
Report Abuse
pwnedu46 is not online. pwnedu46
Joined: 23 May 2009
Total Posts: 7534
12 Jun 2012 10:17 PM
"I don't know how to add an effective minimum to Random"

return (Results[Cur] % Max) + 1 + minimum


----------
    ~pwnedu46, wiki writer~
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
12 Jun 2012 10:20 PM
Quite embarrassing how I couldn't think of something simple as that.....
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
12 Jun 2012 10:23 PM
Wait, that doesn't seem right...
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
12 Jun 2012 10:26 PM
Yeah, That's not right, I tried doing random numbers between 3 and 5 and got this:

5
6
4
8
7
7
6
8
4
5
Report Abuse
pwnedu46 is not online. pwnedu46
Joined: 23 May 2009
Total Posts: 7534
12 Jun 2012 11:13 PM
return (Results[Cur] % (Max-minimum)) + 1 + minimum
Report Abuse
rayoma is not online. rayoma
Joined: 13 Nov 2009
Total Posts: 1911
13 Jun 2012 12:38 AM
randomVal*(max-min)+min
Report Abuse
rayoma is not online. rayoma
Joined: 13 Nov 2009
Total Posts: 1911
13 Jun 2012 12:42 AM
Nevernind, I didn't realize your function wouldn't return a number between 0 and 1 like most random functions. Just use math.sin(math.exp(seed)). Works a lot easier, better and makes a lot more sense.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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