|
| 25 Jan 2016 05:46 PM |
A segment of a code I'm writing is:
-- local rand = math.random(100) if rand >= 50 then --
Every time a certain part is touched, this segment of code is run (it is inside a function called by the touched event.) For some reason, the "if rand >= 50 then" statement is literally always satisfied. I don't see how it's possible that I'm generating a random number from 1 to 100, then running the code if that number is equal to or above 50, yet the condition is always satisfied?
|
|
|
| Report Abuse |
|
|
|
| 25 Jan 2016 05:47 PM |
| add print(rand) under local rand = math.random(100) |
|
|
| Report Abuse |
|
|
|
| 25 Jan 2016 05:50 PM |
doesn't the > go after =?
local rand = math.random(100) if rand =>50 then
If I had a siggy it would be right here. |
|
|
| Report Abuse |
|
|
|
| 25 Jan 2016 05:50 PM |
Nvm
If I had a siggy it would be right here. |
|
|
| Report Abuse |
|
|
Aethex
|
  |
| Joined: 16 Oct 2011 |
| Total Posts: 2193 |
|
|
| 25 Jan 2016 05:52 PM |
| Put math.randomseed(tick()) at the top for a "more random" approach. |
|
|
| Report Abuse |
|
|
|
| 25 Jan 2016 05:56 PM |
Hmm, it printed nothing but "93" the first test, then nothing but "94" the next two tests. Also, I am using math.randomseed(tick())
|
|
|
| Report Abuse |
|
|
|
| 25 Jan 2016 06:03 PM |
You aren't testing enough You just happened to get 94 twice. |
|
|
| Report Abuse |
|
|
|
| 25 Jan 2016 06:05 PM |
Don't set the seed more than once. If you need to set the seed, do not use tick() as the seed without doing math.
This is the best way to set the seed that anyone has ever posted on the forums. math.randomseed(tick()%1*1e6) |
|
|
| Report Abuse |
|
|
|
| 25 Jan 2016 06:06 PM |
No, no, I mean invididual testing sessions.
I ran in to the door and it printed "93" like 30 times for every last touch I made.
|
|
|
| Report Abuse |
|
|
|
| 25 Jan 2016 06:09 PM |
| Can we see more of your script? |
|
|
| Report Abuse |
|
|