# Help - Second random number being ignored ????

Hi, I wonder if someone could help me I am very new to codea and lua (2 days) and am having a problem getting a variable to
Recreate a random number second time round.

Basically the code is supposed to create an ellipse that expands and shrinks in a random place on the screen.
This works ok for the first ellipse but when the second eclipse is generated in a random x,y coordinate the random variable that I use for the x variable works but not for the y variable resulting in the ellipse appearing randomly up an down the x axis. This is my code the variable that is giving me the problem is marked in capitals with ??? and named myplace.

Any help you can give would be appreciated

``````myradius = 1
mycount = 1
myplace=math.random(50,700)
myplace2=math.random(50,700)

-- Use this function to perform your initial setup
function setup()
print("Hello World!")
watch("myplace")
watch("myplace2")
watch("mycount")

end

-- This function gets called once every frame
function draw()
-- This sets the background color to black
background(0, 255, 216, 255)

translate(myplace,myplace2)

if mycount < 2 then
if myradius < 20 then
fill(myplace,7,0,myplace)

else
mycount = mycount + 1
end
else
fill(myplace,7,0,myplace)
sound("pickup",234)
if myradius < 2 then
mycount = 1
myplace=math.random(50,700) -- THIS RANDOM NUMBER GETS IGNORED ?????????
myplace2=math.random(50,700)
end
end

-- Do your drawing here
ellipseMode(3)

end
``````

sorry here is the code formatted a bit better ( not sure why cut and paste doesn’t format properly)

mycount = 1

myplace=math.random(50,700)

myplace2=math.random(50,700)

– Use this function to perform your initial setup

function setup()

``````print("Hello World!")
``````

watch(“myplace”)

watch(“myplace2”)

watch(“mycount”)

end

– This function gets called once every frame

function draw()

``````-- This sets the background color to black

background(0, 255, 216, 255)

translate(myplace,myplace2) -- my place variable never changes ????????
``````

if mycount < 2 then

``````    if myradius < 20 then

fill(myplace,7,0,myplace)

else

mycount = mycount + 1

end

else

fill(myplace,7,0,myplace)

sound("pickup",234)

if myradius < 2 then

mycount = 1

myplace=math.random(50,700) -- THIS RANDOM NUMBER GETS IGNORED ?????????

myplace2=math.random(50,700)

end

end

-- Do your drawing here
``````

ellipseMode(3)

end

The forum uses Markdown Extra for input formatting. Code blocks can either be indented by 4 spaces or put between “fences”: `~~~` on a line by itself at the start and end. I corrected the original post (you can delete the second post if you like).

I can’t explain it. Possible change this to a bug in th forum and put something in the tracker.

The workaround is to put

wth = math.random(50,700) before the one that is stuck.

Thanks ipda For the work around. I’ll do as you say and post as a bug
Is there a better way of doing a pulsing ellipse or a pulsing sprite even.
The reason I’m saying is that I fill the background with the grass block sprites however when I do this the pulsing ellipse redraws far to slow. I guess this is because the draw function is having to recreate the entire background every frame. I tried building the pulsing ellipse using a for loop that built it in one frame however this is way too fast. Is there a way of setting the background up once without have to recreate it on every frame

I think it’s the random vs sound bug that’s been reported a couple of times:
http://twolivesleft.com/Codea/Talk/discussion/36/sound-breaks-math.random#Item_4

If you remove the sound, should work

Thanks ruilov you are correct I removed the sound and it worked as expected. I think I’ll stick to Ipda41001’ work around though I Need the sound. Any thoughts on my background painting issue see my previous comment

backingmode(retained) and then only draw what is changing like only the grass sprites near the ellipse may help