real random numbers

This is a discussion on real random numbers within the C Programming forums, part of the General Programming Boards category; Hi, is there an existing function in C like rand(), but which creates real random numbers? newatC...

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

  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,262
    >> 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
    21,457
    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.
    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

  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, 09: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, 04:51 PM

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