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
 

Pull random values out of a table

Previous Thread :: Next Thread 
ScriptingRevolution is not online. ScriptingRevolution
Joined: 19 Sep 2015
Total Posts: 528
18 Apr 2016 07:09 PM
I have a table for example: List = {9,91,3,23,40} How would i print a random number out of the table given?
Report Abuse
darthpyro is not online. darthpyro
Joined: 18 Aug 2009
Total Posts: 3569
18 Apr 2016 07:15 PM
print(List[math.random(#List)])
Report Abuse
Lecturous is not online. Lecturous
Joined: 17 Aug 2013
Total Posts: 1096
18 Apr 2016 07:17 PM
print(List[math.random(1, #List)])

Explanation:
You can get values out of arrays by using an index, like this:
List[1] -- it would get the first value out of the table

So we can use a random number between 1 and the total amount of values in the array as an index.
List[math.random(1, #List)]
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