How do i make a random value lower than a specific number value?
Asked by
6 years ago Edited 6 years ago
If you don't like reading skip to the end
So i have 3 random number
1 | local random 1 = math.random( 1 , 10 ) |
2 | local random 2 = math.random( 1 , 10 ) |
3 | local random 3 = math.random() |
Now let's say if the value of the random3 is 0 then the value of random1 and random2 can be anywhere between 1 and 10, but if the value of random3 is 1 then the value of random2 must be lower than random1. But the value of random 1, 2 must always be between 1 and 10.
1 | local random 3 = math.random() |
3 | local random 1 = math.random( 1 , 10 ) |
4 | local random 2 = math.random( 1 , 10 ) |
6 | local random 1 = math.random( 2 , 10 ) |
Now the question is in line 7, how do i make the value lower than the value i get on random1, for example if i get the value of 5 on random1 then the value of random2 must be lower than 5 which means it must be between 1 and 4, i also made the random1 get a value between 2,10 because if it gets 1 then that won't work because there isn't anything lower than 1 that is higher than 1.
I mean i could do this
01 | local random 3 = math.random() |
03 | local random 1 = math.random( 1 , 10 ) |
04 | local random 2 = math.random( 1 , 10 ) |
06 | local random 1 = math.random( 2 , 10 ) |
08 | local random 2 = math.random( 1 , 9 ) |
09 | until random 2 < random 1 |
it would work but if there is an alternative way other than using repeat or a long list of "if else" then i would take it. And also i need to change 2 textlabel from the 2 random values so, the current script would be like this.
01 | local number 1 = workspace.Number 1. SurfaceGui.TextLabel |
02 | local number 2 = workspace.Number 2. SurfaceGui.TextLabel |
04 | local function variable () |
05 | local random 3 = math.random() |
07 | local random 1 = math.random( 1 , 10 ) |
08 | local random 2 = math.random( 1 , 10 ) |
09 | number 1. Text = tostring (random 1 ) |
10 | number 2. Text = tostring (random 2 ) |
12 | local random 1 = math.random( 2 , 10 ) |
13 | number 1. Text = tostring (random 1 ) |
15 | local random 2 = math.random( 1 , 9 ) |
16 | number 2. Text = tostring (random 2 ) |
17 | until random 2 < random 1 |
21 | anyeventlistener:Connect(variable) |
So overall the problem is..
How do i make a random value lower than another random value