random number generator

This is a discussion on random number generator within the C Programming forums, part of the General Programming Boards category; Is there a way to generate random numbers in c like you can in c++, and more specifically could you ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    43

    random number generator

    Is there a way to generate random numbers in c like you can in c++, and more specifically could you generate a hex value...I am thinking you could gennerate geo random numbers and then our the together to make ur hex value taking into account a-f

    Also could if there us a way to gennerate random numbers could you put a range on them...for instance they l have to be positive signed integer...and be in the ranfe from -f

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,773
    Quote Originally Posted by begginer
    Is there a way to generate random numbers in c like you can in c++
    Actually, the current C++ standard library's random number generation facilities were inherited from C, so unless you are relying on the C++ TR1 RNG facilities, or those from another library, you should already be familiar with srand and rand.

    Quote Originally Posted by begginer
    more specifically could you generate a hex value...I am thinking you could gennerate geo random numbers and then our the together to make ur hex value taking into account a-f
    Hexadecimal is just a number base. You would generate the pseudorandom number, then display it in your desired base, e.g., using the %x format specifier for printf.

    Quote Originally Posted by begginer
    Also could if there us a way to gennerate random numbers could you put a range on them...for instance they l have to be positive signed integer...and be in the ranfe from -f
    Read Prelude's article on using rand for some ideas.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue w/ Guess My Number Program
    By mkylman in forum C++ Programming
    Replies: 5
    Last Post: 08-23-2007, 01:31 AM
  2. Good Random Number Generator
    By MethodMan in forum C Programming
    Replies: 4
    Last Post: 11-18-2004, 05:38 AM
  3. How do I restart a random number sequence.
    By jeffski in forum C Programming
    Replies: 6
    Last Post: 05-29-2003, 02:40 PM
  4. how to link random number generator with cpu?
    By chris285 in forum C++ Programming
    Replies: 5
    Last Post: 04-28-2003, 05:26 AM
  5. Seeding Random Number Generator
    By zdude in forum C++ Programming
    Replies: 2
    Last Post: 09-05-2002, 03:10 PM

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