Click here to Skip to main content
15,888,461 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Generate Random Number between min and max range and where numbers can't repeat themselves. Pin
Adam Roderick J21-Jan-10 19:17
Adam Roderick J21-Jan-10 19:17 
GeneralRe: Generate Random Number between min and max range and where numbers can't repeat themselves. Pin
Le@rner21-Jan-10 19:28
Le@rner21-Jan-10 19:28 
GeneralRe: Generate Random Number between min and max range and where numbers can't repeat themselves. Pin
Adam Roderick J21-Jan-10 19:36
Adam Roderick J21-Jan-10 19:36 
AnswerRe: Generate Random Number between min and max range and where numbers can't repeat themselves. Pin
Chris Losinger21-Jan-10 19:25
professionalChris Losinger21-Jan-10 19:25 
GeneralRe: Generate Random Number between min and max range and where numbers can't repeat themselves. Pin
Le@rner21-Jan-10 19:31
Le@rner21-Jan-10 19:31 
GeneralRe: Generate Random Number between min and max range and where numbers can't repeat themselves. Pin
Rajesh R Subramanian21-Jan-10 19:34
professionalRajesh R Subramanian21-Jan-10 19:34 
GeneralRe: Generate Random Number between min and max range and where numbers can't repeat themselves. Pin
Le@rner21-Jan-10 19:49
Le@rner21-Jan-10 19:49 
AnswerRe: Generate Random Number between min and max range and where numbers can't repeat themselves. Pin
CPallini21-Jan-10 21:39
mveCPallini21-Jan-10 21:39 
Extracting numbers from a bag...

const int N = 20; // bag size
int num[N]; //the numbers
int i;
for (i=0; i<N; i++)// initialize the sequence
{
  num[i] = i+1; 
}

for (int i=0; i<N-1; i++) // scramble the sequence
{
  int r = rand() % (N-i); // choose a number in the 'unextracted' sequence
  // put num[r] at the end of the sequence, since it was extracted
  // this is achieved by swapping r and N-1-i items.
  int temp = num[N-1-i];
  num[N-1-i] = num[r];
  num[r]= temp;
}
//print out the scrambled sequence
for (i=0; i<N; i++)
{
  cout << num[i] << endl;
}


Smile | :)

If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.

This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke

[My articles]

AnswerRe: Generate Random Number between min and max range and where numbers can't repeat themselves. Pin
David Crow22-Jan-10 4:21
David Crow22-Jan-10 4:21 
QuestionThe Boss and the Worker Pin
Rozis21-Jan-10 13:34
Rozis21-Jan-10 13:34 
AnswerRe: The Boss and the Worker Pin
Mattias G21-Jan-10 13:45
Mattias G21-Jan-10 13:45 
GeneralRe: The Boss and the Worker Pin
Rozis22-Jan-10 12:06
Rozis22-Jan-10 12:06 
AnswerRe: The Boss and the Worker Pin
iceman861621-Jan-10 15:03
iceman861621-Jan-10 15:03 
GeneralRe: The Boss and the Worker Pin
Rozis22-Jan-10 12:07
Rozis22-Jan-10 12:07 
AnswerRe: The Boss and the Worker Pin
Adam Roderick J21-Jan-10 17:51
Adam Roderick J21-Jan-10 17:51 
GeneralRe: The Boss and the Worker Pin
Rozis22-Jan-10 12:05
Rozis22-Jan-10 12:05 
Questionc++ integration subroutine. Pin
mrby12321-Jan-10 12:50
mrby12321-Jan-10 12:50 
AnswerRe: c++ integration subroutine. Pin
Mattias G21-Jan-10 12:55
Mattias G21-Jan-10 12:55 
GeneralRe: c++ integration subroutine. Pin
mrby12321-Jan-10 13:05
mrby12321-Jan-10 13:05 
GeneralRe: c++ integration subroutine. Pin
Mattias G21-Jan-10 13:21
Mattias G21-Jan-10 13:21 
QuestionCompiling an assembly file with Visual Studio Pin
Jim Crafton21-Jan-10 8:44
Jim Crafton21-Jan-10 8:44 
AnswerRe: Compiling an assembly file with Visual Studio Pin
Jim Crafton21-Jan-10 8:47
Jim Crafton21-Jan-10 8:47 
QuestionDialog hang Pin
Member 686483921-Jan-10 8:22
Member 686483921-Jan-10 8:22 
AnswerRe: Dialog hang Pin
Mattias G21-Jan-10 12:39
Mattias G21-Jan-10 12:39 
GeneralRe: Dialog hang Pin
Member 686483922-Jan-10 6:38
Member 686483922-Jan-10 6:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.