Click here to Skip to main content
15,908,834 members
Home / Discussions / C#
   

C#

 
AnswerRe: Seeding Random Number Generator Pin
Dave Kreskowiak8-Jun-12 7:50
mveDave Kreskowiak8-Jun-12 7:50 
Your call to Next:
int randomNumber = randomNum.Next(0,1);

will always return 0 because the lower limit (0) is INCLUSIVE, meaning it will be included in the possible range of values and the upper limit (1) is EXCLUSIVE, meaning that it will NOT be included in the range of possible values.

So, since Next always return an integer (whole number) and your result set goes from 0 to 0, your code will always return 0.

To return 0 or 1, you have to change the range to:
int randomNumber = randomNum.Next(0,2);


Try reading the documentation on Random.Next(int32, int32)[^].

If you want decimal values greater than or equal to 0 and LESS THAN (NOT EQUAL TO!) 1, you'll have to call Random.Double() instead. This will, of course, return a number of type double, not int.


Oh! and your "seed" value sucks if you're looking for anything close to "true" randomness. You're limiting yourself to only 936,000 different sequences of pseudo-random numbers.

Since the default constructor of Random will initialize the generator with the value in the system clock, it has the capability of generating 4.2 billion different random number sequences.


modified 8-Jun-12 14:08pm.

GeneralRe: Seeding Random Number Generator Pin
Paul Conrad8-Jun-12 12:08
professionalPaul Conrad8-Jun-12 12:08 
AnswerRe: Seeding Random Number Generator Pin
PIEBALDconsult8-Jun-12 11:25
mvePIEBALDconsult8-Jun-12 11:25 
QuestionPBX and C# and TAPI Pin
jojoba20117-Jun-12 22:47
jojoba20117-Jun-12 22:47 
AnswerRe: PBX and C# and TAPI Pin
Dave Kreskowiak8-Jun-12 3:24
mveDave Kreskowiak8-Jun-12 3:24 
QuestionRe: PBX and C# and TAPI Pin
jojoba20118-Jun-12 4:47
jojoba20118-Jun-12 4:47 
AnswerRe: PBX and C# and TAPI Pin
Dave Kreskowiak8-Jun-12 7:45
mveDave Kreskowiak8-Jun-12 7:45 
QuestionRe: PBX and C# and TAPI Pin
jojoba20118-Jun-12 7:57
jojoba20118-Jun-12 7:57 
AnswerRe: PBX and C# and TAPI Pin
Dave Kreskowiak8-Jun-12 8:06
mveDave Kreskowiak8-Jun-12 8:06 
QuestionRe: PBX and C# and TAPI Pin
jojoba20118-Jun-12 8:16
jojoba20118-Jun-12 8:16 
AnswerRe: PBX and C# and TAPI Pin
Dave Kreskowiak8-Jun-12 10:13
mveDave Kreskowiak8-Jun-12 10:13 
QuestionRe: PBX and C# and TAPI Pin
jojoba20118-Jun-12 20:36
jojoba20118-Jun-12 20:36 
AnswerRe: PBX and C# and TAPI Pin
Dave Kreskowiak9-Jun-12 4:56
mveDave Kreskowiak9-Jun-12 4:56 
Questionsystem.web.mail do note save sentitem Pin
GinoPittaro19647-Jun-12 22:37
GinoPittaro19647-Jun-12 22:37 
AnswerRe: system.web.mail do note save sentitem Pin
egenis7-Jun-12 23:55
egenis7-Jun-12 23:55 
GeneralRe: system.web.mail do note save sentitem Pin
GinoPittaro19648-Jun-12 0:02
GinoPittaro19648-Jun-12 0:02 
GeneralRe: system.web.mail do note save sentitem Pin
egenis8-Jun-12 0:31
egenis8-Jun-12 0:31 
AnswerRe: system.web.mail do note save sentitem Pin
Bernhard Hiller8-Jun-12 3:03
Bernhard Hiller8-Jun-12 3:03 
AnswerRe: system.web.mail do note save sentitem Pin
Simon_Whale8-Jun-12 3:55
Simon_Whale8-Jun-12 3:55 
QuestionHow to upload apicture into a picturebox in C# Pin
Member 90915607-Jun-12 21:27
Member 90915607-Jun-12 21:27 
AnswerRe: How to upload apicture into a picturebox in C# Pin
Richard MacCutchan7-Jun-12 21:55
mveRichard MacCutchan7-Jun-12 21:55 
GeneralRe: How to upload apicture into a picturebox in C# Pin
Member 90915608-Jun-12 0:19
Member 90915608-Jun-12 0:19 
QuestionHow to fetch data from database in lables in asp.net using three tier architecture Pin
mohansahu7-Jun-12 20:47
mohansahu7-Jun-12 20:47 
AnswerRe: How to fetch data from database in lables in asp.net using three tier architecture Pin
Abhinav S7-Jun-12 20:54
Abhinav S7-Jun-12 20:54 
QuestionC# linq to sql Pin
dcof7-Jun-12 7:15
dcof7-Jun-12 7:15 

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.