i trying to pick 1 or 100 but I don’t know-how.
1 Like
local randomnumber = math.random(1,100)
print(randomnumber)
This picks a number between 1 and 100 not 1 or 100
you can do
local num = math.random(1, 2) == 1 and 100 or 1
print(num) -- will either be 1 or 100
If the randomnumber is 1, it’ll be 100. If the number is 2 it’ll variable will be 1.
never mind, i tryed putting the print in a loop without the variable in it too
it’ll print 100.
It’s just luck really. The script works fine.
also to be sure u can do
for i = 1, 150, 1 do
local num = math.random(1, 2) == 1 and 100 or 1
print(num) -- will either be 1 or 100
end
as u can see it’ll print 100
1 Like
100^(random:NextInteger(0,1))
100^0 = 1
100^1 = 100
1 Like
A rather interesting way would be:
local num = math.clamp(((1000 * math.random(-2,1))+1),1,100)
Another interesting way would be:
local num = table.pack(1,100)[math.random(1,2)]
You can also do it this way I found using linear regression y=ax+b
local num = 99*(math.random(1,2))-98
1 Like
local result = math.random(1,2)
local number
if result == 1 then
number = 1
else
number = 100
end
local result = 1 + math.random(0,1)*99
print(result)
To test if it is random:
local One = 0
local Hundred = 0
for i = 1, 1000 do
local result = 1 + math.random(0,1)*99
if result == 1 then
One+=1
else
Hundred+=1
end
end
print("1 occured: "..One.." time!")
print("100 occured: "..Hundred.." time!")
Maybe this?
local num = math.random(1,2)
if num == 2 then
print("1")
else
print("100")
end
2 Likes
In this instance, you should use elseif num == 1
just incase we want to do this:
local num = math.random(1,100)
if num == 1 then
print("1")
elseif num == 100 then
print("100")
end
sorry for bumping btw
1 Like