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: math.random Always returning the same value

Previous Thread :: Next Thread 
lombardo2 is not online. lombardo2
Joined: 30 Nov 2008
Total Posts: 1604
10 Dec 2012 04:27 PM
math.random always returns the same value when you use the minimum and maximum number that signed 32 bit can represent as arguments.

Why?
Report Abuse
xSIXx is not online. xSIXx
Joined: 06 Aug 2010
Total Posts: 9202
10 Dec 2012 04:29 PM
wat
Report Abuse
lombardo2 is not online. lombardo2
Joined: 30 Nov 2008
Total Posts: 1604
10 Dec 2012 04:32 PM
Try:

print(math.random(-21 47 48 3 648, 2 1 47 4 83 64 7))

remove the spaces, for some silly reason Roblox is filtering the numbers
Report Abuse
ArceusInator is not online. ArceusInator
Joined: 10 Oct 2009
Total Posts: 30553
10 Dec 2012 04:32 PM
Rather than erroring, roblox prefers to give the wrong result.

Try subtracting 1 from the max and adding 1 to the min.
Report Abuse
AbsoluteLOL is not online. AbsoluteLOL
Joined: 01 Dec 2012
Total Posts: 3939
10 Dec 2012 04:35 PM
Well, to start: math.random() is pseudo-random. Use math.randomseed() within math.random. Example:
var = math.random(math.randomseed(1), math.randomseed(10))
print(var)

If you want whole numbers, simply use math.ceil or math.floor. Also, if I'm correct, this should also solve your problem.

~ I like pudding ◕‿◕ ~
Report Abuse
lombardo2 is not online. lombardo2
Joined: 30 Nov 2008
Total Posts: 1604
10 Dec 2012 04:36 PM
^I know that... I'm just asking why it happens
Report Abuse
lombardo2 is not online. lombardo2
Joined: 30 Nov 2008
Total Posts: 1604
10 Dec 2012 04:37 PM
And by the way, that would error
Report Abuse
AbsoluteLOL is not online. AbsoluteLOL
Joined: 01 Dec 2012
Total Posts: 3939
10 Dec 2012 04:37 PM
I understand you know this, I'm saying it could be a viable solution to the problem, as I'm assuming you want this to stop.
Anyways, I haven't any clue why this happens. Blame Sorcus.

~ I like pudding ◕‿◕ ~
Report Abuse
AbsoluteLOL is not online. AbsoluteLOL
Joined: 01 Dec 2012
Total Posts: 3939
10 Dec 2012 04:38 PM
Yeah, I just noticed the fail I made. Ignore the code.

~ I like pudding ◕‿◕ ~
Report Abuse
lombardo2 is not online. lombardo2
Joined: 30 Nov 2008
Total Posts: 1604
10 Dec 2012 04:41 PM
Yeah, it's Sorcus fault!!

No, really it intrigues me why it always return the same value without setting the seed.
Report Abuse
xSIXx is not online. xSIXx
Joined: 06 Aug 2010
Total Posts: 9202
10 Dec 2012 04:41 PM
that's like saying:

print(math.random(-math.huge,math.huge))

and that prints out the exact same value.

maybe it's because you have a massive range.
Report Abuse
lombardo2 is not online. lombardo2
Joined: 30 Nov 2008
Total Posts: 1604
10 Dec 2012 04:45 PM
^Wow, more intriguing, print(math.random(math.huge, math.huge)) prints exactly the same as print(math.random(-21 47 48 3 648, 2 1 47 4 83 64 7)) (Without spaces): -2 147 48 36 48
Report Abuse
xSIXx is not online. xSIXx
Joined: 06 Aug 2010
Total Posts: 9202
10 Dec 2012 04:46 PM
that's what i said hurrrr
Report Abuse
AbsoluteLOL is not online. AbsoluteLOL
Joined: 01 Dec 2012
Total Posts: 3939
10 Dec 2012 04:48 PM
Is it possible that you've "broken" the math.huge barrier?
Let's face it, math.huge isn't truly infinite.

~ I like pudding ◕‿◕ ~
Report Abuse
AbsoluteLOL is not online. AbsoluteLOL
Joined: 01 Dec 2012
Total Posts: 3939
10 Dec 2012 04:54 PM
Actually, now that I think of it, math.huge isn't that small. So scratch my last "did you break it?" statement.

~ I like pudding ◕‿◕ ~
Report Abuse
Luc599345 is not online. Luc599345
Joined: 25 Jul 2008
Total Posts: 1169
10 Dec 2012 05:06 PM
"now that I think of it, math.huge isn't that small."

I thought the 'huge' in 'math.huge' made it kind of obvious O.o
Report Abuse
needyapple is not online. needyapple
Joined: 22 Jan 2011
Total Posts: 785
10 Dec 2012 05:06 PM
Because, your giving it little space to call something out

var = math.random(1, 10)
for i = 1, 10 do
print(var)
end

Perhaps?
Report Abuse
AbsoluteLOL is not online. AbsoluteLOL
Joined: 01 Dec 2012
Total Posts: 3939
10 Dec 2012 05:10 PM
"I thought the 'huge' in 'math.huge' made it kind of obvious O.o"
Sorry. I thought "huge" was another word for "miniscule".

/sarcasm

~ I like pudding ◕‿◕ ~
Report Abuse
Seranok is not online. Seranok
Joined: 12 Dec 2009
Total Posts: 11083
10 Dec 2012 05:56 PM
The source code for the math.random function can be found on Lua's site.
Report Abuse
SolarCrane is not online. SolarCrane
Forum Moderator
Joined: 03 Jul 2012
Total Posts: 116
11 Dec 2012 03:06 PM
I believe the reason is because the interval given to math.random is >= 2^31 - 1.

Notice how the barrier of when math.random begins to act funny dances around an interval of 2^31 - 1:
> print(2^31 - 1)
Works:
> print(math.random(0, 2^31 - 2))
Funny:
> print(math.random(0, 2^31 - 1))
> print(math.random(-1, 2^31 - 2))
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
11 Dec 2012 06:42 PM
SO MUCH FAIL :(
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
11 Dec 2012 06:42 PM
:(
Report Abuse
Drezmor is not online. Drezmor
Joined: 10 Nov 2011
Total Posts: 41
11 Dec 2012 06:52 PM
when I did random in C with a loop I got one result always

I fixed with global variables


-----------------------
rResult=0;

for i=1,10 do
rResult=math.random(n,n);
end;
-----------------------

I didn't read the all post of this thread...
Report Abuse
xXxMoNkEyMaNxXx is not online. xXxMoNkEyMaNxXx
Joined: 03 Oct 2008
Total Posts: 3120
11 Dec 2012 10:16 PM
The random funciton must have something to do with the modulo for that number, it would then cycle to the same value.
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