User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 392,047 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,318 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 2128 | Replies: 1
Reply
Join Date: Feb 2005
Posts: 4
Reputation: s47221288 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
s47221288 s47221288 is offline Offline
Newbie Poster

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

  #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

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.
Last edited by alc6379 : Feb 23rd, 2005 at 3:44 pm. Reason: added [code] tags
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2005
Posts: 43
Reputation: Siersan is an unknown quantity at this point 
Rep Power: 4
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++)

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C++ Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 11:27 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC