random value?

This is a discussion on random value? within the C++ Programming forums, part of the General Programming Boards category; How would i produce a random value? Code: int x = random(0,100); ?...

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    168

    random value?

    How would i produce a random value?

    Code:
    int x = random(0,100);
    ?
    -Felix
    Rots Soft
    If the facts don't fit the theory, change the facts.
    Albert Einstein (1879 - 1955)

  2. #2
    Registered User
    Join Date
    Sep 2003
    Posts
    135
    Use rand() (and seed first with srand()). Look them up in your C++ book or try this tutorial:

    http://www.robertjacobs.fsnet.co.uk/random.htm

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    53
    edit : lol nevermind...seems there was a much more easy way posted right before me
    Its all a matter of willpower

  4. #4
    o0o
    o0o is offline
    Registered User o0o's Avatar
    Join Date
    Dec 2003
    Posts
    37
    I guess it should be like this

    Code:
    int x = randomValue;
    
    randomValue = 0 + rand()%100;

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >randomValue = 0 + rand()%100;
    I suggest you read both our FAQ and the tutorial posted previously to learn why this is not the best idea.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. random to int?
    By psyadam in forum C# Programming
    Replies: 7
    Last Post: 07-22-2008, 08:09 PM
  2. Lesson #3 - Math
    By oval in forum C# Programming
    Replies: 2
    Last Post: 04-27-2006, 08:16 AM
  3. Another brain block... Random Numbers
    By DanFraser in forum C# Programming
    Replies: 2
    Last Post: 01-23-2005, 04:51 PM
  4. How do I restart a random number sequence.
    By jeffski in forum C Programming
    Replies: 6
    Last Post: 05-29-2003, 02:40 PM
  5. Best way to generate a random double?
    By The V. in forum C Programming
    Replies: 3
    Last Post: 10-16-2001, 04:11 PM

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