Linux

  1. Home
  2. Computing & Technology
  3. Linux
Linux / Unix Command: srand
Command Library

NAME

rand, srand - random number generator.  

SYNOPSIS

#include <stdlib.h>

int rand(void);

void srand(unsigned int seed);
 

DESCRIPTION

The rand() function returns a pseudo-random integer between 0 and RAND_MAX.

The srand() function sets its argument as the seed for a new sequence of pseudo-random integers to be returned by rand(). These sequences are repeatable by calling srand() with the same seed value.

If no seed value is provided, the rand() function is automatically seeded with a value of 1.  

RETURN VALUE

The rand() function returns a value between 0 and RAND_MAX. The srand() returns no value.  

SEE ALSO

random(3), srandom(3), initstate(3), setstate(3)


Important: Use the man command (% man) to see how a command is used on your particular computer.

>> Linux/Unix Command Library

>> Shell Command Library

Explore Linux

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Linux

  1. Home
  2. Computing & Technology
  3. Linux

©2009 About.com, a part of The New York Times Company.

All rights reserved.