so i have 4 integer that are
int m = rand() % 3+ 0;
int n = rand() % 3 + 0;
int x = rand() % 3 + 0;
int y = rand() % 3 + 0;

and i want to random in 0-3 range so how can i random 4 interger
in different number between 0 - 3 ?? what is loop for this problem ?

exam. Firsttime ; m = 1
n = 0
x = 3
y =2

this is my old code

int main()
{
 srand(time(NULL));
 int array[4];
 array[0]=rand() % 3 + 0;  
 for(int i=1;i<=3;i++)
 {
    array[i]=rand() % 3 + 0;
    if ((array[i]=array[i-1])||(array[i]=array[i-2])||(array[i]   =array[i-3]))
   {
           array[i]=rand() % 3 + 0;
   }
 }
 cout<<array[0]<<array[1]<<array[2]<<array[3]<<endl;
 system("pause");
 return 0;
}

ps.- Use in c or c++
Thank you.

Member Avatar for Siersan

if ((array=array[i-1])||(array=array[i-2])||(array =array[i-3]))

You probably want to use == instead of =. The former is comparison and the latter is assignment. Aside from that, your loop seems to work okay. What exactly are you trying to do?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.