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
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: math.random() between non-integers?

Previous Thread :: Next Thread 
SLY3 is not online. SLY3
Joined: 10 Jul 2008
Total Posts: 1700
27 Jan 2015 09:23 AM
Simple question that I'm surprised I don't actually know the answer to, how do you do math.random() between two numbers that aren't whole numbers?

If you do math.random(0.2,0.8) it returns 0.
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
27 Jan 2015 09:29 AM
math.random(2, 8) / 10


print(math.random(2, 8) / 10) -->0.2 to 0.8
Report Abuse
SLY3 is not online. SLY3
Joined: 10 Jul 2008
Total Posts: 1700
27 Jan 2015 09:30 AM
That's actually a really good idea, thanks.
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
27 Jan 2015 09:32 AM
it would be cool if math.random had a third argument where it was like

math.random(0.2, 0.8, 0.1)

so its like

between 0.2 and 0.8, and it'll be a tenth of a number


or like

math.random(10, 100, 10)

would be either
10
20
30
40
50
60
70
80
90
or 100
Report Abuse
ChiefDelta is not online. ChiefDelta
Joined: 05 Nov 2010
Total Posts: 13071
27 Jan 2015 09:35 AM
Do it like Java where you manipulate a call to math.random() with no arguments and like multiply it.
Report Abuse
lordrambo is not online. lordrambo
Joined: 16 Jun 2009
Total Posts: 20628
27 Jan 2015 09:52 AM
Pretty much every language has support for both, and it's really not worth the effort it would take.

(math.random() * (0.8 - 0.2)) + 0.2
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
27 Jan 2015 09:59 AM
do
local omath = math;
math = setmetatable({}, {__index = math});
function math.random(...)
if #{...} >= 3 then
return omath.random(...)*{...}[3];
else
return omath.random(...)
end
end
end
local math = math;
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