Thread: generate randon number without using rand()

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    3

    Question generate randon number without using rand()

    hi everyone,
    can anyone of u tell me how to generate a random number without using any c library function like rand().
    the number generated should be between 0-99 only.

    reply as soon as possible.
    thank you
    sk_agarwals

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    34
    If you only need a random number every couple of seconds or so, you could try using the milliseconds returned from the ftime function. Use the remainder after dividing by 100 to keep it within the range desired.

    Code:
    #include <stdio.h>
    #include <sys/timeb.h>
    
    
    int main(int argc, char* argv[])
    {
        struct _timeb tstruct;
     
    	_ftime( &tstruct );
    	printf( "milliseconds: %u\n", tstruct.millitm % 100);
    	
    	return 0;
    }
    clu82

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    3

    Exclamation Re: generate randon number without using rand()

    hi clu82,
    your program is not working it is giving 2 errors so please correct it.
    i am using a dos base turboc++ compiler keep this in mind.

    thank you.

    siddharth

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    34
    siddharth,

    Copy the error messages you are getting, into this thread. I am using VC++ 6.0 on Win2000. Look in your documentation to see if you have the _ftime() function and the _timeb structure. Is your compiler even finding the sys/timeb.h file?

    If your compiler doesn't have the above items, it should have something similar.

    clu82

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. random isn't really random?
    By azsquall in forum C++ Programming
    Replies: 88
    Last Post: 06-14-2008, 02:16 PM
  2. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  3. Nim Trainer
    By guesst in forum Game Programming
    Replies: 3
    Last Post: 05-04-2008, 04:11 PM
  4. Stone Age Rumble
    By KONI in forum Contests Board
    Replies: 30
    Last Post: 04-02-2007, 09:53 PM
  5. Perfect number...
    By Argo_Jeude in forum C++ Programming
    Replies: 8
    Last Post: 07-12-2005, 01:53 PM