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
|
  |
| Joined: 06 Aug 2010 |
| Total Posts: 9202 |
|
| |
|
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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| Joined: 30 Nov 2008 |
| Total Posts: 1604 |
|
|
| 10 Dec 2012 04:37 PM |
| And by the way, that would error |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 10 Dec 2012 04:38 PM |
Yeah, I just noticed the fail I made. Ignore the code.
~ I like pudding ◕‿◕ ~ |
|
|
| Report Abuse |
|
|
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
|
  |
| 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
|
  |
| 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
|
  |
| Joined: 06 Aug 2010 |
| Total Posts: 9202 |
|
| |
|
|
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| Joined: 22 Nov 2008 |
| Total Posts: 21686 |
|
| |
|
nate890
|
  |
| Joined: 22 Nov 2008 |
| Total Posts: 21686 |
|
| |
|
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 |
|
|
|
| 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 |
|
|