Thread: how to make random numbers?

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    1

    how to make random numbers?

    Hey, im pretty new, and exploring C++, not the best started programming i know, but anyway..

    I want to make a simple program with a random number between 1 and 3, im not too sure how to do this. Any help would be great.

  2. #2
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    522
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  3. #3
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753

    yeah...

    srand(time(NULL)); //Just put this in, you need it

    x=1 + rand() % 3 //Random number 1 through 3

    make sure you know how the modulus operator works.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. random numbers
    By h_howee in forum C++ Programming
    Replies: 3
    Last Post: 12-21-2005, 02:56 PM
  2. Unique random numbers
    By aydin in forum C Programming
    Replies: 7
    Last Post: 11-23-2004, 12:21 PM
  3. Generating Random Numbers
    By FromHolland in forum C++ Programming
    Replies: 6
    Last Post: 06-16-2003, 09:05 AM
  4. Generate random numbers in Lucky7 project using C#
    By Grayson_Peddie in forum C# Programming
    Replies: 1
    Last Post: 04-11-2003, 11:03 PM
  5. programming with random numbers
    By xstudent in forum C Programming
    Replies: 13
    Last Post: 05-21-2002, 01:36 AM