Click to See Complete Forum and Search --> : I NEED HELP FAST PLEASE! Random
invitro
Feb 20th, 2001, 08:25 PM
How do i make a random number using rand between
0 and 1
like .45
ect.
Thanks
I need this ASAP!!
HarryW
Feb 20th, 2001, 09:38 PM
this should work:
// couple of includes you need
#include <stdlib.h>
#include <time.h>
// the random number code
srand( (unsigned)time( NULL ) );
float randomnum = (float)rand() / (float)RAND_MAX; // RAND_MAX = 32767
// now use randomnum however you like
That's really all there is to it. rand() returns an integer between 0 and RAND_MAX (which is 32767) so you can get pretty much any kind of random number from it.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.