Thread: real random numbers

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    16

    real random numbers

    Hi,

    is there an existing function in C like rand(), but which creates real
    random numbers?

    newatC

  2. #2
    Just kidding.... fnoyan's Avatar
    Join Date
    Jun 2003
    Location
    Still in the egg
    Posts
    275
    Well, since computers cannot think like any human being, "random numbers" are always depend on something (like clock cycles for example!)

    You can use srand() for better results.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    http://faq.cprogramming.com/cgi-bin/...&id=1043284385

    By real - you mean really random, cannot be predicted in advance using any known algorithmic technique?

    Or real as in a floating point number between 0.0 and 1.0 say?
    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.

  4. #4
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Quote Originally Posted by fnoyan
    Well, since computers cannot think like any human being, "random numbers" are always depend on something (like clock cycles for example!)

    You can use srand() for better results.
    hint: humans are far worse random number generators than computers have the potential to be...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  5. #5
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    >> Or real as in a floating point number between 0.0 and 1.0 say?

    I think he means that. You could make a random function which multiplies a few random numbers together and returns the result. You could even use rand() to get the number of times things are multiplied! Oh, the possibilities!

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    hmm... wouldnt multiplication of (pseudo-)random numbers change the distribution? For example, there is a probability of 1/6 to get a given number from rolling a 6 sided die, but rolling the die twice (or using two dice) would not lead to a probability of 1/36 for each possible number.
    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

  7. #7
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    no it doesn't, it creates a weighted randomness... that's why 7 is a 'lucky' number.

    Code:
     2  3  4  5  6  7
     3  4  5  6  7  8
     4  5  6  7  8  9
     5  6  7  8  9 10
     6  7  8  9 10 11
     7  8  9 10 11 12
    
    Ocurrances:
    1 has 0 possibilities
    2 has 1 possibilities
    3 has 2 possibilities
    4 has 3 possibilities
    5 has 4 possibilities
    6 has 5 possibilities
    7 has 6 possibilities
    [edit]
    "no it doesn't" was said in agreement to you laser
    [/edit]
    Last edited by major_small; 09-01-2006 at 12:10 PM.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  8. #8
    Registered User
    Join Date
    Sep 2006
    Posts
    16
    Hi,

    thank you for your answers, and thank you for the link Salem.

    newatC

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Generating a sequence of numbers in a random order
    By mirbogat in forum C Programming
    Replies: 15
    Last Post: 08-12-2008, 02:01 PM
  2. Question about random numbers
    By Kempelen in forum C Programming
    Replies: 2
    Last Post: 07-02-2008, 06:28 AM
  3. %16 with double
    By spank in forum C Programming
    Replies: 11
    Last Post: 03-05-2006, 10:10 PM
  4. Generating 100k to 1 million unique random numbers
    By Ariod in forum C Programming
    Replies: 4
    Last Post: 08-26-2005, 12:59 PM
  5. Another brain block... Random Numbers
    By DanFraser in forum C# Programming
    Replies: 2
    Last Post: 01-23-2005, 05:51 PM