Random number generator? [SOLVED]
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Random number generator? [SOLVED]
I can't get love.math.random() to generate a real random number. It only generates 0. It is in the love.load() function but it does not work.
Last edited by Walbal on Fri Jun 09, 2023 10:15 pm, edited 2 times in total.
OBEY LOADING |||||
Re: Random number generator?
Is that all the code? Because i use that function and it works exactly that number range i did many times.
Or are you asking for a real number type like 12.45? If that is the case then ehm.. i smile because it looks silly that way
local r=love.math.random(1,1000)/100
This would get you a number between 1.00 to 10.00
Re: Random number generator?
hi, might want to include code that proves your assertion; transcribing code from an image is work and prone to error. here's a piece of test code, also provides platform info (prints to console so run it from shell using lovec.exe):
i wasn't able to replicate the issue:
if you need a float, you can't specify the range. it returns (0.0, 1.0) which you can scale and offset to whatever you need:
https://love2d.org/wiki/love.math.random
Code: Select all
local seedlo, seedhi = love.math.getRandomSeed()
local minimum, maximum = 1, 10 -- uniform inclusive range of returned integers
print('platform ', love.system.getOS())
print('version ', love.getVersion())
print('seed ', seedlo, seedhi)
print('range ', minimum, maximum)
local i = 1
while i <= 20 do
local rnum = love.math.random(minimum, maximum)
print('rnum'..tostring(i),rnum)
assert((rnum >= minimum) and (rnum <=maximum), tostring(rnum)..' is out of range!')
i = i+1
end
Code: Select all
platform Windows
version 11 3 0 Mysterious Mysteries
seed 1686337932 0
range 1 10
rnum1 2
rnum2 4
rnum3 3
rnum4 1
rnum5 10
rnum6 2
rnum7 5
rnum8 1
rnum9 8
rnum10 9
rnum11 9
rnum12 10
rnum13 7
rnum14 8
rnum15 3
rnum16 6
rnum17 4
rnum18 7
rnum19 6
rnum20 5
https://love2d.org/wiki/love.math.random
Re: Random number generator?
Hi, sorry I did not include code. How should I send it?
OBEY LOADING |||||
Re: Random number generator?
And also, I am trying to get an int but it always just returns 0. Maybe it is something with the graphics system because I had to use love.graphics.print() instead of just print().
OBEY LOADING |||||
Re: Random number generator?
Oh, it was the graphics system, thank you guys so much for helping!
OBEY LOADING |||||
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 2 guests