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
 

Re: Is math.random() broken for anyone else?

Previous Thread :: Next Thread 
wonderful72pike is not online. wonderful72pike
Joined: 13 Jul 2010
Total Posts: 7009
19 Mar 2016 10:23 AM
I'm trying to get a random number between 1 and 5 using this:

math.random(1, 5)

And every single time it gives me 5. So I tried randomseed(tick()) and then it gave me 3 every single time. I've run this about 20 times so far and it has given me the exact same number *every single time*.

Has this happened to anyone?
Report Abuse
c9_io is not online. c9_io
Joined: 15 Feb 2014
Total Posts: 2642
19 Mar 2016 10:24 AM
You're probably doing something wrong. (actually yes you are)


#code "オタク"
Report Abuse
wonderful72pike is not online. wonderful72pike
Joined: 13 Jul 2010
Total Posts: 7009
19 Mar 2016 10:28 AM
I know I'm not doing something wrong, I have isolated it down to that line. I've tried calling it from an external function, I tried using tick(), I even tried adding 1 to it just to see what it gave me and it did this:

> 6
> 6
> 6
> 6
> 6

For some reason it just won't give me a random number.
Report Abuse
wonderful72pike is not online. wonderful72pike
Joined: 13 Jul 2010
Total Posts: 7009
19 Mar 2016 10:29 AM
Like I know a lot of people on this forum say that and then it turns out they are, but I've been doing this for 3 years and I can't see any way that I can be writing that out wrong.
Report Abuse
DarthStrantax is not online. DarthStrantax
Joined: 31 May 2011
Total Posts: 2610
19 Mar 2016 10:30 AM
Only randomseed once
Also post full code
Report Abuse
c9_io is not online. c9_io
Joined: 15 Feb 2014
Total Posts: 2642
19 Mar 2016 10:30 AM
Are you setting it as a constant or overriding it every time


#code --// オタク
Report Abuse
wonderful72pike is not online. wonderful72pike
Joined: 13 Jul 2010
Total Posts: 7009
19 Mar 2016 10:32 AM
I'm overriding it with a new local variable, here's the full function:

function formGrid()
repeat
local num = math.random(1, 5)
print(num)
if num == 5 then
done = true
end
until done == true
end

formGrid()

Here's my Output:

> 5

The first number it goes to is 5 *every single time*.
Report Abuse
wonderful72pike is not online. wonderful72pike
Joined: 13 Jul 2010
Total Posts: 7009
19 Mar 2016 10:34 AM
My problem was I tried to seed it every time it ran, seeding it once worked o_o

Thank you SO MUCH!
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