how to make a random variable value?
Posted: Wed Jan 16, 2008 5:11 pm
There's a variable, and i'd like to put its value as random between 0 and 10. How to do that?
Game Editor discussion board
http://game-editor.com/forum/
my_variable = rand(10);
my variable = rand(10);
if (my variable == 0 ||my variable == 2 ||my variable == 4 ||my variable == 6 ||my variable == 8 ||my variable == 10)
{
xvelocity = -5;
}
else if (my variable == 1 ||my variable == 3 ||my variable == 5 ||my variable == 7 ||my variable == 9)
{
yvelocity = -5;
}
if (my_variable == 0 || my_variable ==2 || my_variable == 4 || my_variable == 6 || my_variable == 8 || my_variable == 10)
{
xvelocity = -5;
}
else if (my_variable == 1 || my_variable ==3 || my_variable == 5 || my_variable == 7 || my_variable == 9)
{
yvelocity = -5;
}
if (my_variable == 0)
{
xvelocity = -5;
}
else if (my_variable == 1)
{
yvelocity = -5;
}
my_variable = rand(10);
if (my_variable == 0 || 2 || 4 || 6 || 8 || 10)
{
xvelocity = -5;
}
else if (my_variable == 1 || 3 || 5 || 7 || 9)
{
yvelocity = -5;
}
diormeh wrote:uuummm... not really look sondise was trying to do this :my_variable = rand(10);
if (my_variable == 0 || 2 || 4 || 6 || 8 || 10)
{
xvelocity = -5;
}
else if (my_variable == 1 || 3 || 5 || 7 || 9)
{
yvelocity = -5;
}
i was giving the code in complete form.
my_variable = rand(10);
if (!my_variable & 1) // check to see if number is even
{
xvelocity = -5;
}
else if (my_variable & 1) check to see if number is odd
{
yvelocity = -5;
}