Click here to Skip to main content
15,927,744 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Generalstruct _timeb Question Pin
Nick Parker10-Jun-04 7:25
protectorNick Parker10-Jun-04 7:25 
GeneralRe: struct _timeb Question Pin
Michael Dunn10-Jun-04 8:15
sitebuilderMichael Dunn10-Jun-04 8:15 
GeneralRe: struct _timeb Question Pin
Nick Parker10-Jun-04 8:30
protectorNick Parker10-Jun-04 8:30 
GeneralC++ Random Question Pin
bobski220010-Jun-04 6:21
bobski220010-Jun-04 6:21 
GeneralRe: C++ Random Question Pin
jmkhael10-Jun-04 6:25
jmkhael10-Jun-04 6:25 
GeneralRe: C++ Random Question Pin
Graham Bradshaw10-Jun-04 6:27
Graham Bradshaw10-Jun-04 6:27 
GeneralRe: C++ Random Question Pin
Rick York10-Jun-04 6:32
mveRick York10-Jun-04 6:32 
GeneralRe: C++ Random Question Pin
Cohen10-Jun-04 6:44
Cohen10-Jun-04 6:44 
rand() returns pseudo random numbers rather than real random numbers. This is why you always get the same value. You can work your way around this by setting the random seed, before you invoke rand(). Seed is a number which is used inside the rand() function to produce the sequence of these pseudo random numbers.

So, different seed value gives you different sequence of numbers. Common trick is to give the current time as seed number as this gives you a different sequence each time you run your application. You can set the seed like this:

srand(static_cast<unsigned>(time(0)));

Make this function call before you use rand() for the first time.

If you wan't the numbers be in a spesified range (between 1 and 100) you must use the following line instead of just invoking rand().

random = 1 + (rand() % 100);

rand() returns numbers between 0 (?) and RAND_MAX (== big number, depends on you compiler I think) and the above line takes a modulus from the returned value and this conveniently scales the result between 0 and 99.

Hope this helps,

Cohen
GeneralRe: C++ Random Question Pin
bobski220010-Jun-04 6:47
bobski220010-Jun-04 6:47 
GeneralRe: C++ Random Question Pin
David Crow10-Jun-04 9:08
David Crow10-Jun-04 9:08 
GeneralRe: C++ Random Question Pin
Cohen10-Jun-04 6:50
Cohen10-Jun-04 6:50 
GeneralProblems overloading htons, htonl, ntohl, &amp; ntohs Pin
Wheatbread10-Jun-04 5:47
Wheatbread10-Jun-04 5:47 
GeneralRe: Problems overloading htons, htonl, ntohl, & ntohs Pin
jmkhael10-Jun-04 5:50
jmkhael10-Jun-04 5:50 
GeneralRe: Problems overloading htons, htonl, ntohl, &amp; ntohs Pin
Wheatbread10-Jun-04 6:21
Wheatbread10-Jun-04 6:21 
GeneralRe: Problems overloading htons, htonl, ntohl, &amp; ntohs Pin
jmkhael10-Jun-04 6:23
jmkhael10-Jun-04 6:23 
GeneralRe: Problems overloading htons, htonl, ntohl, &amp; ntohs Pin
Wheatbread10-Jun-04 6:32
Wheatbread10-Jun-04 6:32 
GeneralRe: Problems overloading htons, htonl, ntohl, &amp; ntohs Pin
jmkhael10-Jun-04 6:37
jmkhael10-Jun-04 6:37 
GeneralRe: Problems overloading htons, htonl, ntohl, &amp; ntohs Pin
Wheatbread10-Jun-04 6:46
Wheatbread10-Jun-04 6:46 
GeneralStandalone MFC program Pin
hdaly10-Jun-04 5:17
hdaly10-Jun-04 5:17 
GeneralRe: Standalone MFC program Pin
Navin10-Jun-04 5:23
Navin10-Jun-04 5:23 
Generaltroubles with templates Pin
Kamis10-Jun-04 5:04
Kamis10-Jun-04 5:04 
GeneralRe: troubles with templates Pin
Diddy10-Jun-04 5:22
Diddy10-Jun-04 5:22 
GeneralActiveX control for Ms Exchange Server info Pin
dels_cpp10-Jun-04 4:24
dels_cpp10-Jun-04 4:24 
GeneralDate/Time Picker 'Enter' key behavior Pin
JYoder10-Jun-04 4:11
JYoder10-Jun-04 4:11 
GeneralRe: Date/Time Picker 'Enter' key behavior Pin
bikram singh10-Jun-04 15:45
bikram singh10-Jun-04 15:45 

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.