Click here to Skip to main content
16,015,047 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Library file redefinition error Pin
fefe.wyx10-Sep-07 17:05
fefe.wyx10-Sep-07 17:05 
GeneralRe: Library file redefinition error Pin
palanirajan10-Sep-07 17:32
palanirajan10-Sep-07 17:32 
AnswerRe: Library file redefinition error Pin
john563210-Sep-07 19:57
john563210-Sep-07 19:57 
GeneralRe: Library file redefinition error Pin
jhwurmbach10-Sep-07 21:50
jhwurmbach10-Sep-07 21:50 
QuestionUpper limit of rand() function Pin
rp_suman10-Sep-07 15:45
rp_suman10-Sep-07 15:45 
AnswerRe: Upper limit of rand() function Pin
fefe.wyx10-Sep-07 17:00
fefe.wyx10-Sep-07 17:00 
GeneralRe: Upper limit of rand() function Pin
rp_suman10-Sep-07 17:36
rp_suman10-Sep-07 17:36 
AnswerLoaded dice! Pin
Stephen Hewitt10-Sep-07 17:47
Stephen Hewitt10-Sep-07 17:47 
I assume you’re using code like this:
int val = rand()%10 + 1;

This will not produce evenly distributed random numbers!
‘rand’ generates random numbers from 0 to ‘RAND_MAX’ (32767).
Below if a list of ranges, each range maps from 1 to 10 (e.g. 0->1, 1->2, ..., 10->1, 11->2, etc):

0-9 10-19 20-29 …. 32750-32759 32760-32767 (32769)

Note the last range is smaller than the rest! The number in brackets is the value we would have to use as the maximum to make it the same size.

Here’s a breakdown of the last range:
32760 -> 1
32761 -> 2
32762 -> 3
32763 -> 4
32764 -> 5
32765 -> 6
32766 -> 7
32767 -> 8

This means the numbers from 1-8 will be slightly more likely to occur than 9 and 10 because 1-8 appear in all ranges whereas 9 and 10 appear in all ranges except the last!

If I were you I'd use Boost's Random[^] library.


Steve

QuestionWhy is my atof() code doesn't work? Pin
TooShy2Talk10-Sep-07 15:45
TooShy2Talk10-Sep-07 15:45 
AnswerRe: Why is my atof() code doesn't work? Pin
rp_suman10-Sep-07 15:51
rp_suman10-Sep-07 15:51 
GeneralRe: Why is my atof() code doesn't work? Pin
TooShy2Talk10-Sep-07 15:57
TooShy2Talk10-Sep-07 15:57 
GeneralRe: Why is my atof() code doesn't work? Pin
rp_suman10-Sep-07 16:30
rp_suman10-Sep-07 16:30 
QuestionRe: Why is my atof() code doesn't work? Pin
TooShy2Talk10-Sep-07 20:13
TooShy2Talk10-Sep-07 20:13 
AnswerRe: Why is my atof() code doesn't work? [modified] Pin
rp_suman11-Sep-07 5:45
rp_suman11-Sep-07 5:45 
GeneralRe: Why is my atof() code doesn't work? Pin
TooShy2Talk11-Sep-07 18:01
TooShy2Talk11-Sep-07 18:01 
AnswerRe: Why is my atof() code doesn't work? Pin
Nelek11-Sep-07 23:12
protectorNelek11-Sep-07 23:12 
Questionsetup project Pin
Franken10-Sep-07 9:16
Franken10-Sep-07 9:16 
QuestionRe: setup project Pin
David Crow10-Sep-07 10:29
David Crow10-Sep-07 10:29 
AnswerRe: setup project Pin
Franken10-Sep-07 10:32
Franken10-Sep-07 10:32 
GeneralRe: setup project Pin
David Crow10-Sep-07 10:37
David Crow10-Sep-07 10:37 
GeneralRe: setup project Pin
Franken10-Sep-07 10:49
Franken10-Sep-07 10:49 
QuestionRe: setup project Pin
David Crow10-Sep-07 11:06
David Crow10-Sep-07 11:06 
AnswerRe: setup project Pin
Franken10-Sep-07 11:18
Franken10-Sep-07 11:18 
AnswerRe: setup project Pin
carrivick11-Sep-07 11:09
carrivick11-Sep-07 11:09 
GeneralRe: setup project Pin
Franken12-Sep-07 2:41
Franken12-Sep-07 2:41 

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.