954,173 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Random Different Number in each loop ?? HLP Me PLZ (c or c++)

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.

s47221288
Newbie Poster
4 posts since Feb 2005
Reputation Points: 10
Solved Threads: 0
 
if ((array[i]=array[i-1])||(array[i]=array[i-2])||(array[i] =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?

Siersan
Light Poster
45 posts since Jan 2005
Reputation Points: 12
Solved Threads: 2
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You