Click here to Skip to main content
15,891,431 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to embed or encrypt or hide a dictionary wordlist txt file Pin
EliottA19-Aug-09 5:39
EliottA19-Aug-09 5:39 
GeneralRe: How to embed or encrypt or hide a dictionary wordlist txt file Pin
alrsds19-Aug-09 20:17
alrsds19-Aug-09 20:17 
QuestionAvoiding Random() Class generate the same number Pin
gamer112719-Aug-09 3:20
gamer112719-Aug-09 3:20 
AnswerRe: Avoiding Random() Class generate the same number Pin
hairy_hats19-Aug-09 3:23
hairy_hats19-Aug-09 3:23 
GeneralRe: Avoiding Random() Class generate the same number Pin
gamer112719-Aug-09 3:32
gamer112719-Aug-09 3:32 
GeneralRe: Avoiding Random() Class generate the same number Pin
hairy_hats19-Aug-09 3:39
hairy_hats19-Aug-09 3:39 
GeneralRe: Avoiding Random() Class generate the same number Pin
gamer112719-Aug-09 3:45
gamer112719-Aug-09 3:45 
GeneralRe: Avoiding Random() Class generate the same number Pin
Dave Kreskowiak19-Aug-09 4:00
mveDave Kreskowiak19-Aug-09 4:00 
If you don't supply a seed value to the RNG when you create it, it uses the current timer value, down the the millisecond it supplies, as the seed. Since your code (needlessly) creates a new RNG every interation of the loop, multiple iterations are using the same timer value as their seed, and hence, comming up with the same stream of "random" numbers.

All you do is create the RNG once, in the class' constructor or some other appropriate place that is executed only once. You don't need to create a new RNG every time you need a new random number.

Also, the RNG does not guarantee that each number in the set of returned number will be unique. You'll have to wrap it in an implementation that keeps track of the numbers already returned and check to see if the next number returned is already in the set and grab a new number if it is. This will, of course, get slower and slower as the number of unique numbers you use gets larger and larger.


A guide to posting questions on CodeProject[^]



Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic
     2006, 2007, 2008
But no longer in 2009...




AnswerRe: Avoiding Random() Class generate the same number Pin
Eddy Vluggen19-Aug-09 3:26
professionalEddy Vluggen19-Aug-09 3:26 
AnswerRe: Avoiding Random() Class generate the same number Pin
gamer112719-Aug-09 4:13
gamer112719-Aug-09 4:13 
GeneralRe: Avoiding Random() Class generate the same number Pin
PIEBALDconsult19-Aug-09 4:29
mvePIEBALDconsult19-Aug-09 4:29 
GeneralRe: Avoiding Random() Class generate the same number Pin
gamer112719-Aug-09 4:34
gamer112719-Aug-09 4:34 
GeneralRe: Avoiding Random() Class generate the same number Pin
PIEBALDconsult19-Aug-09 7:16
mvePIEBALDconsult19-Aug-09 7:16 
GeneralRe: Avoiding Random() Class generate the same number Pin
Keith Barrow19-Aug-09 4:33
professionalKeith Barrow19-Aug-09 4:33 
GeneralRe: Avoiding Random() Class generate the same number Pin
PIEBALDconsult19-Aug-09 7:17
mvePIEBALDconsult19-Aug-09 7:17 
GeneralRe: Avoiding Random() Class generate the same number Pin
Eddy Vluggen19-Aug-09 4:35
professionalEddy Vluggen19-Aug-09 4:35 
GeneralRe: Avoiding Random() Class generate the same number Pin
Saksida Bojan19-Aug-09 5:49
Saksida Bojan19-Aug-09 5:49 
AnswerRe: Avoiding Random() Class generate the same number Pin
PIEBALDconsult19-Aug-09 7:45
mvePIEBALDconsult19-Aug-09 7:45 
QuestionWhy \r\n? Pin
hairy_hats19-Aug-09 3:00
hairy_hats19-Aug-09 3:00 
AnswerRe: Why \r\n? Pin
Keith Barrow19-Aug-09 3:09
professionalKeith Barrow19-Aug-09 3:09 
GeneralRe: Why \r\n? Pin
hairy_hats19-Aug-09 3:14
hairy_hats19-Aug-09 3:14 
GeneralRe: Why \r\n? Pin
Eddy Vluggen19-Aug-09 3:21
professionalEddy Vluggen19-Aug-09 3:21 
GeneralRe: Why \r\n? Pin
hairy_hats19-Aug-09 3:47
hairy_hats19-Aug-09 3:47 
GeneralRe: Why \r\n? Pin
Dan Neely19-Aug-09 4:33
Dan Neely19-Aug-09 4:33 
AnswerRe: Why \r\n? Pin
PIEBALDconsult19-Aug-09 4:51
mvePIEBALDconsult19-Aug-09 4:51 

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.