Results 1 to 6 of 6

Thread: Random Number in a specified range

  1. #1

    Thread Starter
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772

    Random Number in a specified range

    I know how to get a random number using the time as a seed, but how can i have it be between two speficied numbers? (say, 65 to 90)
    Alcohol & calculus don't mix.
    Never drink & derive.

  2. #2
    jim mcnamara
    Guest
    You want random capital letters... chars from 65 to to 90....
    Try:

    PHP Code:
    unsigned char r=0;
    while (
    r<65){
          
    rand() % 91;
    }
    printf("%c \n" r); 

  3. #3

    Thread Starter
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    Lol, so you saw that Thanks for the help.
    Alcohol & calculus don't mix.
    Never drink & derive.

  4. #4

    Thread Starter
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    Is it possible to have multiple ranges? ( I am trying to get any alphanumeric character)
    Alcohol & calculus don't mix.
    Never drink & derive.

  5. #5
    Zaei
    Guest
    Code:
    r = rand() % (max - min) + min
    Z.

  6. #6

    Thread Starter
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    Thanks, that helps a lot.
    Alcohol & calculus don't mix.
    Never drink & derive.

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