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
 

How to randomize a table with a percent outcome?

Previous Thread :: Next Thread 
TheBeastSword is online. TheBeastSword
Joined: 28 Oct 2011
Total Posts: 213
11 Jun 2017 08:20 PM
Hey. How would I make a table with a percentage and randomize it?

tables = {
["Outcome1"] = 5%
["Outcome2"] = 95%
}

local random = tables[math.random(1,#tables)]

and have Outcome2 have a 95% chance of being chosen while Outcome1 has a 5% chance?
Report Abuse
Jonah13249 is not online. Jonah13249
Joined: 09 Oct 2009
Total Posts: 2105
11 Jun 2017 10:17 PM
What's the purpose of the values in those tables?

You can get a random variable with math.random and then use an if statement to control the outcome.

random = math.random()

if random < .05 then
--Outcome 1
else
--Outcome 2
end

The math.random() values give values between 0, and 1 exclusive [0,1) so you can do math if you want to give values between 0 and 100 [0, 100) for convenience --math.random()*100
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