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
 

math.random Question

Previous Thread :: Next Thread 
unholysoda is not online. unholysoda
Joined: 15 May 2010
Total Posts: 9024
27 Jan 2012 11:04 PM
how would i use math.random to choose a radom a random wait time between 1 and 10.
I tried this but it did not work
wait(math.random(1,10))
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
27 Jan 2012 11:05 PM
Maybe try using variables.
Report Abuse
Jammintoad is online. Jammintoad
Joined: 08 Feb 2009
Total Posts: 10239
27 Jan 2012 11:05 PM
You sure it didn't work? that looks perfectly fine, check the rest of the script you have it in.
Also, if you put "math.randomseed(tick())" at the beginning of your script, it makes it truly random.
Report Abuse
grimm343 is not online. grimm343
Joined: 18 Sep 2008
Total Posts: 2796
27 Jan 2012 11:06 PM
wait(math.random(10))
or
wait(math.random(1,10))

Both are correct.
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
27 Jan 2012 11:08 PM
1,10 is better though.
Report Abuse
blueymaddog is not online. blueymaddog
Joined: 23 Sep 2009
Total Posts: 5459
27 Jan 2012 11:10 PM
@miz, y? it's just longer :P
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
27 Jan 2012 11:13 PM
@blue

math.random takes 2 arguements. minimum and maximum. To be specific it's good to say 1, 10
Report Abuse
CrazyBananaMonkey is not online. CrazyBananaMonkey
Joined: 10 Nov 2009
Total Posts: 1599
27 Jan 2012 11:15 PM
@miz,

math.random can only take 1 argument. If so, it'll pick a number btwn 1 and the argument.
Report Abuse
CrazyBananaMonkey is not online. CrazyBananaMonkey
Joined: 10 Nov 2009
Total Posts: 1599
27 Jan 2012 11:15 PM
can take** not can only take.

(Floodcheck: 2 Me: 0)
Report Abuse
darkkiller5555 is not online. darkkiller5555
Joined: 22 Nov 2009
Total Posts: 6359
27 Jan 2012 11:15 PM
Technically it'd be better to do math.random(10) since it's less code and will take up less bytes. Of course, those 2 - 3 digits would be like, 5 bytes. So..Not a big difference.
Report Abuse
unholysoda is not online. unholysoda
Joined: 15 May 2010
Total Posts: 9024
27 Jan 2012 11:17 PM
ok, thanks i figured it out
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
27 Jan 2012 11:18 PM
Yeah but think about it. what if you want it to do 5,10 seconds instead of 1,10?
Report Abuse
CrazyBananaMonkey is not online. CrazyBananaMonkey
Joined: 10 Nov 2009
Total Posts: 1599
27 Jan 2012 11:20 PM
But here he doesn't, so math.random(10); is perfectly fine.
Report Abuse
swmaniac is not online. swmaniac
Joined: 28 Jun 2008
Total Posts: 15773
27 Jan 2012 11:21 PM
"Also, if you put "math.randomseed(tick())" at the beginning of your script, it makes it truly random."

For the billionth time, math.random() is already random. ._. It should already use the system time (returned by tick()) as the random's seed.
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
27 Jan 2012 11:23 PM
@swmaniac

It's really not random when it's small numbers. It's only random when it's maximum is high numbers.
Report Abuse
swmaniac is not online. swmaniac
Joined: 28 Jun 2008
Total Posts: 15773
27 Jan 2012 11:24 PM
...Yes, it is random. It's always random. ._.
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
27 Jan 2012 11:25 PM
It's only random when the maximum number is really high. If the maximum number is like 20 or 10 not really.
Report Abuse
darkkiller5555 is not online. darkkiller5555
Joined: 22 Nov 2009
Total Posts: 6359
27 Jan 2012 11:27 PM
Is it random, however, it's not..Well, as random as we would like it.
Report Abuse
swmaniac is not online. swmaniac
Joined: 28 Jun 2008
Total Posts: 15773
27 Jan 2012 11:29 PM
math.random range 10

local table = {}

for x = 1, 1000 do
local i = math.random(10)
table[i] = table[i] and table[i] + 1 or 1
end

print(unpack(table))

Results:

105 110 84 97 87 95 126 105 100 91

Those numbers should average out to 100 each to be the correct probability.

> print((105+110+84+97+87+95+126+105+100+91)/10)
100

It's perfect at 10 range.
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
27 Jan 2012 11:29 PM
@Dark

It is kinda random you have to admit.
Report Abuse
swmaniac is not online. swmaniac
Joined: 28 Jun 2008
Total Posts: 15773
27 Jan 2012 11:30 PM
At least at range 10 it works out to be the correct probabilities.

Want a further restricted range?
Report Abuse
swmaniac is not online. swmaniac
Joined: 28 Jun 2008
Total Posts: 15773
27 Jan 2012 11:31 PM
math.random range 5

local table = {}

for x = 1, 1000 do
local i = math.random(5)
table[i] = table[i] and table[i] + 1 or 1
end

local a, b, c, d, e = unpack(table)

print(a, b, c, d, e)
print((a+b+c+d+e)/5)

180 203 210 208 199
200
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