Random number

This is a discussion on Random number within the C Programming forums, part of the General Programming Boards category; 1. How to generate 0 and 1 in a random way in C99? 2. How to generate any 2 number ...

  1. #1
    Anirban Ghosh
    Join Date
    Jan 2006
    Posts
    278

    Random number

    1. How to generate 0 and 1 in a random way in C99?
    2. How to generate any 2 number in a random way from 1 to n in C99?

  2. #2
    Chi! whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    8,221

  3. #3
    Anirban Ghosh
    Join Date
    Jan 2006
    Posts
    278
    Anything can be done with inbuilt C functions please?
    I have no knowledge of random number generators! So cannot implement this without theoretical knowledge!

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,820
    Anything can be done with inbuilt C functions please?
    srand() and rand() are part of the C standard library and can be found in <stdlib.h>.

    I have no knowledge of random number generators! So cannot implement this without theoretical knowledge!
    Do something about your ignorance by reading:
    Using rand()
    Random Numbers Tutorial
    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

  5. #5
    Registered User
    Join Date
    Apr 2007
    Location
    Greece
    Posts
    52
    and keep in mind that the "random" numbers from the rand() follow a uniform distribution.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. rapid random number generation problem
    By Newton in forum C Programming
    Replies: 17
    Last Post: 09-19-2008, 02:08 PM
  2. Random number in range generation.
    By hebali in forum C Programming
    Replies: 19
    Last Post: 03-04-2008, 09:46 AM
  3. adding a number to a number
    By bigmac(rexdale) in forum C Programming
    Replies: 11
    Last Post: 10-24-2007, 12:56 PM
  4. random number tutorial
    By 7stud in forum C++ Programming
    Replies: 3
    Last Post: 07-26-2005, 02:41 PM
  5. Random Number Generator
    By Ikurik in forum C++ Programming
    Replies: 16
    Last Post: 08-17-2003, 07:34 PM

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