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
    22,159
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 02:31 AM
  2. Good Random Number Generator
    By MethodMan in forum C Programming
    Replies: 4
    Last Post: 11-18-2004, 06:38 AM
  3. How do I restart a random number sequence.
    By jeffski in forum C Programming
    Replies: 6
    Last Post: 05-29-2003, 03:40 PM
  4. how to link random number generator with cpu?
    By chris285 in forum C++ Programming
    Replies: 5
    Last Post: 04-28-2003, 06:26 AM
  5. Seeding Random Number Generator
    By zdude in forum C++ Programming
    Replies: 2
    Last Post: 09-05-2002, 04:10 PM

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