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 » Scripting Helpers
Home Search
 

Re: math.random Between 2 numbers?

Previous Thread :: Next Thread 
ToonU is not online. ToonU
Joined: 15 Aug 2011
Total Posts: 6303
15 Sep 2012 11:56 AM
How would you get a script to generate a random number between 2 chosen numbers?

Is it possible? I think I've seen it before.

-[ http://www.roblox.com/Build-Brag-V-2-1-place?id=64950819 ]-
Report Abuse
ToonU is not online. ToonU
Joined: 15 Aug 2011
Total Posts: 6303
15 Sep 2012 11:57 AM
I sound like a newby.

-[ http://www.roblox.com/Build-Brag-V-2-1-place?id=64950819 ]-
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
15 Sep 2012 12:50 PM
    print(math.random(2))

> 1

Would be from 1 to 2.

    local RandomNumber=math.random(5, 7)
    
    print(RandomNumber)

> 5

This would be 5 to 7.

    function RandomizeNumbers(Int1, Int2)
     pcall(function() print(math.random(Int1, Int2)) end)
    end

    RandomizeNumbers(1, 2)

> 2

Make sure the lower number is first, if you're using two arguments.

    math.random()

With no arguments, it would be from 0 to 1.

For more information:

http://wiki.roblox.com/index.php/Function_Dump/Mathematical_Functions#math.random


† KMXD †

Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
15 Sep 2012 01:58 PM
If you want between two numbers WITH decimal places (ie, NOT INTEGERS), you can do this:


function ranWithDec(a, b)
    if a < b then
        return math.random()*(b-a)+a
    else
        return math.random()*(a-b)+b
    end
end



Though I'm not sure why you'd want decimal places. Who knows.
Report Abuse
blackboy167thst is not online. blackboy167thst
Joined: 22 Jul 2011
Total Posts: 2468
15 Sep 2012 02:26 PM
for i = 1, 120 do
print(math.random(8, 30))
end

will print 120 numbers between 8-30.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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