hm = {}--height map
hp = {}--height points
lp = {}--low points
mf = 2--mutate factor
function init()
math.randomseed( os.time() )
for i = 0 , 9 do
hm[i] = {}
end
for i = 0 , 9 do
hm[i] = math.random(0,9)
end
end
init()
for i = 0 , 9 do
pon = math.random(0,1)
if i == 0 then
io.write(math.random(math.floor((0 - hm[i+1])/2)))
elseif i == 9 then
io.write(math.random(math.floor((hm[i-1] - 0)/2)))
else
io.write(math.random(math.floor((hm[i-1] - hm[i+1])/2)).." ")
end
io.write(hm[i].." ")
end
Apparently the math in your call to math.random on line 20 is resulting in a number that's less than one. Make sure it's greater than or equal to 1.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit! Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Taehl wrote:Apparently the math in your call to math.random on line 20 is resulting in a number that's less than one. Make sure it's greater than or equal to 1.
but i need a negative value.
so do i have to make a if statement to check if the value is negative , and if so then set it to the minimum of the random function?
like this:
for i = 0 , 9 do
pon = math.random(0,1)
if i == 0 then
if math.floor((0 - hm[i+1])/2) < 0 then
io.write(math.random(math.floor((0 - hm[i+1])/2)),0)
else
io.write(math.random(math.floor((0 - hm[i+1])/2)))
end
elseif i == 9 then
if math.floor((0 - hm[i+1])/2) < 0 then
io.write(math.random(math.floor((0 - hm[i-1])/2)),0)
else
io.write(math.random(math.floor((0 - hm[i-1])/2)))
end
else
if math.floor((0 - hm[i+1])/2) < 0 then
io.write(math.random(math.floor((hm[i-1] - hm[i+1])/2),0).." ")
else
io.write(math.random(math.floor((0 - hm[i+1])/2)))
end
end
io.write(hm[i].." ")
end
A solution that will work is to use the opposite positive number for math.random and then negate the result to get it back to negative. If you need to get a negative number to positive you can use the negation operator, and the same for getting it back to negative. For example:
BlackBulletIV wrote:A solution that will work is to use the opposite positive number for math.random and then negate the result to get it back to negative. If you need to get a negative number to positive you can use the negation operator, and the same for getting it back to negative. For example:
BlackBulletIV wrote:A solution that will work is to use the opposite positive number for math.random and then negate the result to get it back to negative. If you need to get a negative number to positive you can use the negation operator, and the same for getting it back to negative. For example:
Taehl wrote:Apparently the math in your call to math.random on line 20 is resulting in a number that's less than one. Make sure it's greater than or equal to 1.
but i need a negative value.
But math.random() needs a positive value.
If you want to get a random number between -10 and 10 do something like this: