How do you randomly assign a number/integer to more then one object? (Changed)
From ggc
I need some more detail on this question. Let me know if the following describes what you want to do:
x=random.nextInt(3); y=random.nextInt(4);
These statements get two random numbers and store them in different variables. x is one random number between 0 and 2 and y is another random number but between 0 and 3. You can make and use as many random numbers as you want.
You can also use one random number in different places:
x=random.nextInt(3); oval.setScale(x/4.0); rect.setScale(x/5.0);
This uses one random variable x for setting the scale of two different sprites oval and rect
Does this show you what you need to know?
Almost. What I want to do is assign 3 doors a random number on start with 0-2 in the same set of random numbers without creating more random numbers.
Ah, very good question and clarification. See if this code gives you enough of a hint:
int x, y, z;
x=random.nextInt(3);
if(x==0)
{
if(random.nextInt(2)==0)
{
y=1;
z=2;
}
else
{
y=2;
z=1;
}
}
else if(x==1)
{
if(random.nextInt(2)==1)
{
y=0;
z=2;
}
else
{
//you fill in here
}
}
else
{
if(//you fill in here)
{
//you fill in here)
}
else
{
//you fill in here
}
}
//now x, y, and z are randomly assigned 0, 1, or 2 each
- This page was last modified on 7 February 2008, at 13:27.
- This page has been accessed 246 times.
- Privacy policy
- About ggc
- Disclaimers
- Powered by MediaWiki!









