Random Number

This is a discussion on Random Number within the C++ Programming forums, part of the General Programming Boards category; Hi, I need a program to pick a random number between two values. Like: int randomnumber; 0< ramdomnumber <10; cout<<randomnuber;<<endl; ...

  1. #1
    Registered User BigSter's Avatar
    Join Date
    Nov 2001
    Posts
    47

    Cool Random Number

    Hi,
    I need a program to pick a random number between two values.
    Like:

    int randomnumber;
    0< ramdomnumber <10;
    cout<<randomnuber;<<endl;

    Thanks

  2. #2
    0x01
    Join Date
    Sep 2001
    Posts
    88
    I.. think this is what your asking for...

    Code:
    /* Prints out Random numbers only from 0 - 10,
       no more, no less.........................*/
    #include "iostream.h"
    #include "stdlib.h"
    
    int main()
    {
    	cout << "\nRandom Number(s)";
    	cout << "\n---------------------------";
    	
    	/* Print 20 random numbers, numbers can 
    	   only be 0 - 10....................*/
    	for(int idx = 0; idx < 20; idx++)
    	{
    		int i = rand() % 10; // Look here.
    		cout << "\n i equals : " << i << " :";
    	}
    	cout << "\n\n";
    	return 0;
    }

  3. #3
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    I hope that you were joking. Look through the FAQ before you post.

  4. #4
    Registered User BigSter's Avatar
    Join Date
    Nov 2001
    Posts
    47
    That works perfect!
    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. rapid random number generation problem
    By Newton in forum C Programming
    Replies: 17
    Last Post: 09-19-2008, 03:08 PM
  2. Random number in range generation.
    By hebali in forum C Programming
    Replies: 19
    Last Post: 03-04-2008, 10:46 AM
  3. adding a number to a number
    By bigmac(rexdale) in forum C Programming
    Replies: 11
    Last Post: 10-24-2007, 01:56 PM
  4. random number tutorial
    By 7stud in forum C++ Programming
    Replies: 3
    Last Post: 07-26-2005, 03:41 PM
  5. Random Number Generator
    By Ikurik in forum C++ Programming
    Replies: 16
    Last Post: 08-17-2003, 08:34 PM

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