Thread: perfect randomness?

  1. #31
    Registered User cyberCLoWn's Avatar
    Join Date
    Dec 2003
    Location
    South Africa
    Posts
    124
    Woops, forgot <ctime>. But why not use this form of random number generator? Is there something wrong with it? It's quite simple to understand although I'm not sure of it's portability.

  2. #32
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    It's portable.

    What is "wrong" is very simple as long as you don't go too deep into it: rand as implemented by most C runtime libraries doesn't produce a very good number sequence, meaning that it doesn't appear very random.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #33
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    Random = unpredictable and unbiased.

    tu_user,

    Imagine that you have already flipped the coin 99 times. Your results are 50 tales and 49 heads. If you can predict that the next flip will be heads... well, that's not random! Each real coin-flip is an independent random event. The coin doesn't know about or care about it's previous flips!

    rand() is usually good-enough - As long as you (or the user) can't predict the results, your program will be "random enough". Don't worry that there is an underlying deterministic algorithm.

    Unpredictable - The results are not known in advance.

    Unbiased - All results are equally likely. You should not be able to say "I usually get more heads than tails".

    Often, you do want some bias. For example if you are simulating people's weight, a result of 150 lbs should be more likely than 300 lbs.

  4. #34
    Registered User tu_user's Avatar
    Join Date
    Jan 2004
    Posts
    36

    Lightbulb

    Yeah right DougDbug. Thanku. I got it now. Actually I am new to c++ so it will take some time, know what I mean? Anyways I have finally arrived to a conclusion that there is nothin called perfect randomness.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My perfect number assignment...
    By Ninestar in forum C Programming
    Replies: 8
    Last Post: 11-16-2005, 02:47 AM
  2. Perfect Numbers C Program
    By SlayerBlade in forum C Programming
    Replies: 2
    Last Post: 08-28-2005, 05:11 PM
  3. Perfect Number Problem
    By TrazPFloyd in forum C++ Programming
    Replies: 21
    Last Post: 10-20-2002, 11:09 AM
  4. Perfect number
    By TheSki in forum C++ Programming
    Replies: 2
    Last Post: 10-30-2001, 04:34 PM
  5. perfect squares?
    By ahalya in forum C++ Programming
    Replies: 2
    Last Post: 10-14-2001, 09:38 PM