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

C / C++ / MFC

 
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 
AnswerRe: random number that doesn't repeat? Pin
__yb27-Oct-05 2:18
__yb27-Oct-05 2:18 
Hi I'm not sure what u mean:
(1) to fill an array with non-repeating random numbers
or (2) to shuffle array elements

From your code it looks more like 2. It also looks like the [Delete] was pushed here and there...

The technique of marking used elements is not good. If u had an array of 1M the last iteration would lots of time coz u'd repeat it lots of time till u hit the one out million left..

What u should do is this:
<br />
int i, new_array[size], old_array[size];<br />
<br />
for(i=0; i<size; i++) // init old_array<br />
    init(old_array+i);<br />
<br />
// repeat this till size is zero<br />
for(i=0; size>0; i++) {<br />
    // Choose and copy<br />
    new_array[i] = old_array[x=(rand()%size)];<br />
<br />
    // Delete the used element:<br />
    // The most efficient way is to copy the last one into the 'space'<br />
    // and reduce the size.<br />
    // This is allowed coz we don't care for the order in the old array<br />
    old_array[x] = old_array[--size];<br />
}<br />


HTH
Yakov


-- modified at 10:07 Thursday 27th October, 2005
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 
GeneralRe: How to get the actual value? Pin
David Crow27-Oct-05 2:19
David Crow27-Oct-05 2:19 

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.