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

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2005
Posts: 4
Reputation: s47221288 is an unknown quantity at this point 
Solved Threads: 0
s47221288 s47221288 is offline Offline
Newbie Poster

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

 
0
  #1
Feb 20th, 2005
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

  1. int main()
  2. {
  3. srand(time(NULL));
  4. int array[4];
  5. array[0]=rand() % 3 + 0;
  6. for(int i=1;i<=3;i++)
  7. {
  8. array[i]=rand() % 3 + 0;
  9. if ((array[i]=array[i-1])||(array[i]=array[i-2])||(array[i] =array[i-3]))
  10. {
  11. array[i]=rand() % 3 + 0;
  12. }
  13. }
  14. cout<<array[0]<<array[1]<<array[2]<<array[3]<<endl;
  15. system("pause");
  16. return 0;
  17. }

ps.- Use in c or c++
Thank you.
Last edited by alc6379; Feb 23rd, 2005 at 4:44 pm. Reason: added [code] tags
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 45
Reputation: Siersan is an unknown quantity at this point 
Solved Threads: 2
Siersan's Avatar
Siersan Siersan is offline Offline
Speaker of Truth

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

 
0
  #2
Feb 20th, 2005
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?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC