Thread: random numbers between 1500 and 3000

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    66

    random numbers between 1500 and 3000

    I want to generate random numbers between 1500 and 3000. Is there a way to do this using either of the following random number generating code examples?

    Much appreciated.

    Code:
    srand( (unsigned)time( NULL ) );
    printf( "  %d\n", rand() );
    Code:
    random_number = (int) (3000.0*rand()/(RAND_MAX));

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Just use the same code you would use for generating a rndom number between 0 and 1500, and then add 1500 to it.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    66
    Great thinking.

    Thankyou very much.

Popular pages Recent additions subscribe to a feed