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
 

Non-repeating Random Number Generator

Previous Thread :: Next Thread 
BrainSqueezer is not online. BrainSqueezer
Joined: 19 Aug 2009
Total Posts: 432
05 Jan 2014 09:52 PM
Dunno why I've been having so much trouble with this. I need a random number generator that doesn't repeat a number it has already outputted. Can anyone hook me up?
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
05 Jan 2014 09:54 PM
Then it's not even random at all.

local used = {}

local function pickRandom(s,e)
local num
repeat num = math.random(s, e) until not used[num]
used[num] = true
return num
end
Report Abuse
redlo123 is not online. redlo123
Joined: 07 Feb 2013
Total Posts: 231
05 Jan 2014 09:55 PM
seed it first

next, every time it generates a number, add it to an array.
Check if the number has already been generated by looking through the array with loop
Report Abuse
Absurdism is not online. Absurdism
Joined: 18 Jul 2013
Total Posts: 2568
05 Jan 2014 10:00 PM
In fact, a non-repeating random number generator is less random if that's what you're aiming for.
Report Abuse
BrainSqueezer is not online. BrainSqueezer
Joined: 19 Aug 2009
Total Posts: 432
05 Jan 2014 10:09 PM
The reason I needed it (thanks, cntkillme!) was to be able to put items into a table in a random order. If I tried using truly random numbers to iterate over the items, some of them would be picked more than once.

I've been attempting to use the same strategy as redlo and cntkillme for a couple of days now, but it wasn't working for me :/
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
05 Jan 2014 10:42 PM
For that, use a numeric for loop to go through the table, selecting a random element from the table and inserting it into the second table then removing the selected element.
Report Abuse
BrainSqueezer is not online. BrainSqueezer
Joined: 19 Aug 2009
Total Posts: 432
05 Jan 2014 11:33 PM
Will this work for string.gmatch? I guess I'd might as well explain further.

I am trying to scramble a word by exploding it into individual letters, then picking them at random and putting them in another table. Then, I'll combine the scrambled letters again by using table.concat, though I'm getting weird errors there for some reason.
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