I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
ComputingCStdlib.h

rand

Generate random number
+ View version details

Key Facts

Gyroscopic Couple: The rate of change of angular momentum (\inline \tau) = \inline I\omega\Omega (In the limit).
  • \inline I = Moment of Inertia.
  • \inline \omega = Angular velocity
  • \inline \Omega = Angular velocity of precession.


Blaise Pascal (1623-1662) was a French mathematician, physicist, inventor, writer and Catholic philosopher.

Leonhard Euler (1707-1783) was a pioneering Swiss mathematician and physicist.

Interface

#include <stdlib.h>
int rand (void)

Description

Rand function returns a pseudorandom number. The algorithm used in rand function uses a seed to generate the series, which should be initialized to some distinctive value using srand.

Generate Random Number

#include <cstdlib> 
#include <ctime> 
#include <iostream>
 
using namespace std;
 
int main() 
{ 
    srand((unsigned)time(0)); 
    int random_integer; 
    for(int index=0; index<20; index++){ 
        random_integer = (rand()%10)+1; 
        cout << random_integer << endl; 
    } 
}

Output: This example of program will output 20 random numbers from 1 to 10.

Return Values

The rand function returns a pseudo-random integral number between 0 and RAND_MAX (where RAND_MAX is a constant defined in <cstdlib>).

There is no error return.