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: Random (math.random)

Previous Thread :: Next Thread 
Soccer3363 is not online. Soccer3363
Joined: 03 Sep 2013
Total Posts: 42
28 Feb 2014 03:12 PM
How would i get this script to randomly pick a number 1 to 3 every time it goes through the script? (i didnt understand roblox wiki about this topic)

while wait(1) do
if Workspace.Values.Pick.Value == true then
Workspace.Values.Pick.Value = false
ran = math.random(1,3)
if ran == 1 then
Workspace.Values.Tsunami.Value = true
elseif ran == 2 then
Workspace.Values.Flood.Value = true
elseif ran == 3 then
Workspace.Values.Both.Value = true
end
end
end

(i repeated this thread since nobody will answer on an f5 bombed thread)
Report Abuse
Ultraw is not online. Ultraw
Joined: 20 Nov 2010
Total Posts: 6575
28 Feb 2014 03:18 PM
This script should work.
What is happening wrong?
Report Abuse
xWOWZABOYx is not online. xWOWZABOYx
Joined: 05 Aug 2010
Total Posts: 2689
28 Feb 2014 03:20 PM
This should work.

math.random(lowestNumber, highestNumber)

will pick a random integer between lowestNumber and highestNumber.

【◄[ϟ]〓☜✪ xWOWZABOYx; FCOM, SQN COM, Scientist, Veteran, Visionary ✪☞〓[ϟ]►】
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
28 Feb 2014 03:20 PM
Ok,what
Variable = math.random(1,3) does
Is sets variable (using psedueo randomness(or however its spelt))
To a number in between start,and end
Variable = math.random(startpoint,endpoint)
So if "startpoint" was 7 and endpoint was "77" it would pick a random number between 7 and 77
Ex:
Variable = math.random(5,12)
print ("the variable was set to",Variable,"randomly")
Output would be something like

the variable was set to 7 randomly

To get to output
View
-OutPut
Report Abuse
Soccer3363 is not online. Soccer3363
Joined: 03 Sep 2013
Total Posts: 42
28 Feb 2014 03:21 PM
i get the same number for a while though
is there a better way so it's random every time the script goes through?
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
28 Feb 2014 03:26 PM
Well,to make it more random

Var = math.random(30)--will choose a random number up to 30
Var = Var/10--if Var was 20,it'll become "2"

If Var<2 then--the same thing as if the var is 1
--dostuff
elseif Var>1.9 and Var<3 then --the same thing as if the var is 2
--dostuff
elseif Var>2.9 then--the same as if the var is 3
--dostuff
end
Report Abuse
Ultraw is not online. Ultraw
Joined: 20 Nov 2010
Total Posts: 6575
28 Feb 2014 03:28 PM
oldvalue = math.random(1,3)

while true do

newvalue = math.random(1,3)
if newvalue ~= oldvalue then

if Workspace.Values.Pick.Value == true then
Workspace.Values.Pick.Value = false
wait()
oldvalue = newvalue

if ran == 1 then
Workspace.Values.Tsunami.Value = true
elseif ran == 2 then
Workspace.Values.Flood.Value = true
elseif ran == 3 then
Workspace.Values.Both.Value = true
wait()--TIME THE MAP IS UP FOR
end

end
end
end
Report Abuse
Ultraw is not online. Ultraw
Joined: 20 Nov 2010
Total Posts: 6575
28 Feb 2014 03:28 PM
basically mine ensures the same map cannot be picked twice in a row
Report Abuse
Soccer3363 is not online. Soccer3363
Joined: 03 Sep 2013
Total Posts: 42
28 Feb 2014 03:29 PM
@island that makes the same probability
what does math.randomseed do?
ill test...
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
28 Feb 2014 03:31 PM
@ultra
Genius,lol,I was trying to think of a way to do that,ik it was simple,but my brain was off lol..
Ultras will ensure that the same number will not be picked twice inna row

Output:
1
3
2
1
3
2
Never repeats the same number twice :)
Report Abuse
Ultraw is not online. Ultraw
Joined: 20 Nov 2010
Total Posts: 6575
28 Feb 2014 03:33 PM
Yep, thanks for testing
use mine
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
28 Feb 2014 03:33 PM
And mine won't have same probability..I think so anyways
math.random(1,3)
Output:
3
1
2
3
3
Mine:
math.random(30)/10
Output
1.5
2.7
0.6
2.3
1.5
Its diffrent :/
15
27
06
23
15
Report Abuse
xWOWZABOYx is not online. xWOWZABOYx
Joined: 05 Aug 2010
Total Posts: 2689
28 Feb 2014 03:33 PM
Well, that'll happen. That's just luck.

Try:

function randomNumber(low, high) -- separate function should 'save' math.random, not reset
return math.random(low, high)
end

lastNumber = 0
ran = 1

while wait(1) do
if Workspace.Values.Pick.Value == true then
Workspace.Values.Pick.Value = false
while ran == lastNumber do --this
ran = randomNumber(1,3)
wait()
end --this
if ran == 1 then

--etc etc

【◄[ϟ]〓☜✪ xWOWZABOYx; FCOM, SQN COM, Scientist, Veteran, Visionary ✪☞〓[ϟ]►】
Report Abuse
Ultraw is not online. Ultraw
Joined: 20 Nov 2010
Total Posts: 6575
28 Feb 2014 03:35 PM
What do you mean "that'll happen"

No, a number will not be done twice in a row with my script

did you read it?
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
28 Feb 2014 03:35 PM
Erm,ultras is simpler,and easier to understand..
And it never picks the same number twice inna row...
Mine might tho
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
28 Feb 2014 03:37 PM
@OP(original poster,which is soccer)
Use ultras
Report Abuse
Ultraw is not online. Ultraw
Joined: 20 Nov 2010
Total Posts: 6575
28 Feb 2014 03:38 PM
Actually, use this

oldvalue = math.random(1,3)
while true do

newvalue = math.random(1,3)
if newvalue ~= oldvalue then

if Workspace.Values.Pick.Value == true then
Workspace.Values.Pick.Value = false
wait()
if newvalue == 1 then
Workspace.Values.Tsunami.Value = true
elseif newvalue == 2 then
Workspace.Values.Flood.Value = true
elseif newvalue == 3 then
Workspace.Values.Both.Value = true
wait()--TIME THE MAP IS UP FOR

oldvalue = newvalue
end

end
end
end
Report Abuse
xWOWZABOYx is not online. xWOWZABOYx
Joined: 05 Aug 2010
Total Posts: 2689
28 Feb 2014 03:38 PM
Ultra, I was responding to soccer saying he was getting the same number twice in a row.

Guess my response took longer two write than yours :P

Mine just has a small wait loop, a tiny extra function and 2 variables added,. it's the only way I could think of doing it :P

【◄[ϟ]〓☜✪ xWOWZABOYx; FCOM, SQN COM, Scientist, Veteran, Visionary ✪☞〓[ϟ]►】
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