Click here to Skip to main content
15,921,028 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionprint blank pages Pin
valerie9926-Oct-05 5:16
valerie9926-Oct-05 5:16 
Questiontoolbar for Outlook Express Pin
Anonymous26-Oct-05 4:30
Anonymous26-Oct-05 4:30 
AnswerRe: toolbar for Outlook Express Pin
andy14526-Oct-05 23:51
andy14526-Oct-05 23:51 
Questionrandom number that doesn't repeat? Pin
aaadetos26-Oct-05 4:24
aaadetos26-Oct-05 4:24 
AnswerRe: random number that doesn't repeat? Pin
David Crow26-Oct-05 4:30
David Crow26-Oct-05 4:30 
GeneralRe: random number that doesn't repeat? Pin
John R. Shaw26-Oct-05 15:20
John R. Shaw26-Oct-05 15:20 
AnswerRe: random number that doesn't repeat? Pin
toxcct26-Oct-05 5:03
toxcct26-Oct-05 5:03 
AnswerRe: random number that doesn't repeat? Pin
Joe Woodbury26-Oct-05 6:31
professionalJoe Woodbury26-Oct-05 6:31 
One way to obtain an array of random numbers with none repeating is as follows:

Since your random number is to be in the range 1-n, it is better to simply initialize an array of size n with the numbers 1-n:

for (int i = 0; i < size; i++)<br />
    layer_array[i] = i + 1;


(BTW for peformance, don't initialize the array first with "{0}" since you are immediately initializing it one line later.)

Now, seed the random number and then go through the array again exchanging every value with the value at a randomly selected offset:

for (i = 0; i < size; i++)<br />
{<br />
    int dst = rand() % size;<br />
<br />
    // do the swap<br />
    int tmp = layer_array[i];<br />
    layer_array[i] = layer_array[dst];<br />
    layer_array[dst] = tmp;<br />
}




Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke

AnswerRe: random number that doesn't repeat? Pin
__yb27-Oct-05 2:18
__yb27-Oct-05 2:18 
QuestionPlease Help with CAsyncSocket Pin
cgb14326-Oct-05 4:17
cgb14326-Oct-05 4:17 
AnswerRe: Please Help with CAsyncSocket Pin
Moak4-Nov-05 8:39
Moak4-Nov-05 8:39 
Questionefficient 'push&amp;hold' button ? Pin
ganjabro26-Oct-05 4:07
ganjabro26-Oct-05 4:07 
AnswerRe: efficient 'push&amp;hold' button ? Pin
David Crow26-Oct-05 4:25
David Crow26-Oct-05 4:25 
GeneralRe: efficient 'push&amp;hold' button ? Pin
Anonymous26-Oct-05 7:02
Anonymous26-Oct-05 7:02 
QuestionRe: efficient 'push&amp;hold' button ? Pin
David Crow26-Oct-05 7:10
David Crow26-Oct-05 7:10 
AnswerRe: efficient 'push&amp;hold' button ? Pin
ganjabro26-Oct-05 8:35
ganjabro26-Oct-05 8:35 
GeneralRe: efficient 'push&amp;hold' button ? Pin
ganjabro26-Oct-05 8:41
ganjabro26-Oct-05 8:41 
QuestionHow to get the actual value? Pin
ShiningStarPxx26-Oct-05 3:43
ShiningStarPxx26-Oct-05 3:43 
AnswerRe: How to get the actual value? Pin
Cedric Moonen26-Oct-05 3:46
Cedric Moonen26-Oct-05 3:46 
GeneralRe: How to get the actual value? Pin
ShiningStarPxx26-Oct-05 20:08
ShiningStarPxx26-Oct-05 20:08 
GeneralRe: How to get the actual value? Pin
Cedric Moonen26-Oct-05 20:41
Cedric Moonen26-Oct-05 20:41 
AnswerRe: How to get the actual value? Pin
David Crow26-Oct-05 4:04
David Crow26-Oct-05 4:04 
GeneralRe: How to get the actual value? Pin
ShiningStarPxx26-Oct-05 20:00
ShiningStarPxx26-Oct-05 20:00 
GeneralRe: How to get the actual value? Pin
Anonymous26-Oct-05 21:59
Anonymous26-Oct-05 21:59 
GeneralRe: How to get the actual value? Pin
Anonymous26-Oct-05 22:02
Anonymous26-Oct-05 22:02 

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.