random number in range

This is a discussion on random number in range within the Linux Programming forums, part of the Platform Specific Boards category; I need to generate a random number between a range, say 1 - 6. I have looked at rand() and ...

  1. #1
    lgg
    lgg is offline
    Registered User
    Join Date
    Aug 2005
    Posts
    1

    random number in range

    I need to generate a random number between a range, say 1 - 6. I have looked at rand() and it returns random numbers in the integer range. Can anyone tell me how to generate a random number within a certain range.

    Thanks lg

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,672
    Read the FAQ
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Thread should be titled: "random number in FAQ".


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,528
    I need to generate a random number between a range, say 1 - 6. I have looked at rand() and it returns random numbers in the integer range. Can anyone tell me how to generate a random number within a certain range.
    If all else fails, have a look at this. Actually, even if all else doesn't fail, have a look at it.
    Last edited by kermit; 08-14-2005 at 05:17 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Random Number: Mersenne Twister Source Needed
    By mercury529 in forum C++ Programming
    Replies: 12
    Last Post: 11-26-2006, 10:40 AM
  2. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  3. Counting number from a random file
    By kamisama in forum C Programming
    Replies: 42
    Last Post: 02-22-2005, 04:16 PM
  4. Random Numbers within a range OTHER than 1-X
    By Kaelin in forum C++ Programming
    Replies: 11
    Last Post: 02-16-2005, 10:57 AM
  5. How do I restart a random number sequence.
    By jeffski in forum C Programming
    Replies: 6
    Last Post: 05-29-2003, 02:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21