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: Randomness Issue?

Previous Thread :: Next Thread 
coldcoldice is not online. coldcoldice
Joined: 06 Jan 2014
Total Posts: 120
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
128Gigabytes is not online. 128Gigabytes
Joined: 17 Apr 2014
Total Posts: 3616
25 Jan 2016 05:47 PM
add print(rand) under local rand = math.random(100)
Report Abuse
freshhotel is online. freshhotel
Joined: 12 Jun 2012
Total Posts: 827
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
freshhotel is online. freshhotel
Joined: 12 Jun 2012
Total Posts: 827
25 Jan 2016 05:50 PM
Nvm


If I had a siggy it would be right here.
Report Abuse
Aethex is not online. 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
coldcoldice is not online. coldcoldice
Joined: 06 Jan 2014
Total Posts: 120
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
128Gigabytes is not online. 128Gigabytes
Joined: 17 Apr 2014
Total Posts: 3616
25 Jan 2016 06:03 PM
You aren't testing enough
You just happened to get 94 twice.
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
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
coldcoldice is not online. coldcoldice
Joined: 06 Jan 2014
Total Posts: 120
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
128Gigabytes is not online. 128Gigabytes
Joined: 17 Apr 2014
Total Posts: 3616
25 Jan 2016 06:09 PM
Can we see more of your script?
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