Results 1 to 2 of 2

Thread: I NEED HELP FAST PLEASE! Random

  1. #1

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547

    Exclamation

    How do i make a random number using rand between
    0 and 1

    like .45
    ect.
    Thanks

    I need this ASAP!!
    ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?

  2. #2
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    this should work:

    PHP Code:
    // couple of includes you need
    #include <stdlib.h>
    #include <time.h>


    // the random number code
    srand( (unsigned)timeNULL ) );

    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.
    Harry.

    "From one thing, know ten thousand things."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width