Server programming in use...FiaDot

http://www.cplusplus.com/ref/cstdlib/srand.html

  cplusplus.com > reference > cstdlib > srand
srand
<stdlib.h>
  cplusplus.com  
void  rand ( unsigned int seed );

Initialize random number generator.
  Uses seed parameter to set a new starting point for generating random numbers with rand.
  If seed is set to 1 the generator is reinitialized to its initial value as before any call to rand or srand.
  In order to generate true random numbers it is suggested to use as seed a value that changes often, like the one returned by time function included in <time.h> (the number of seconds elapsed since newyear 1970).

Parameters.

seed
An integer value to be used as starting point with the pseudo-random number generator algorithm.

Return Value.
  (none)

Portability.
  Defined in ANSI-C.

Example.

/* rand/srand example */#include <stdio.h>#include <stdlib.h>#include <time.h>int main (){  /* initialize random generator */  srand ( time(NULL) );  /* generate some random numbers */  printf ("A number between 0 and 100: %d\n", rand()%100);  printf ("A number between 20 and 30: %d\n", rand()%10+20);  return 0;}
Output:
A number between 0 and 100: 93
A number between 20 and 30: 21

See also.
  rand

"Steal Article" 카테고리의 다른 글
2006/04/06 07:58 2006/04/06 07:58
Posted by FiaDot
Technical Article/Steal Article l 2006/04/06 07:58

TRACKBACK :: http://fiadot.com/TatterTools/trackback/1750

댓글을 달아 주세요

1  ... 96 97 98 99 100 101 102 103 104  ... 676 

카테고리

전체 (676)
개인 (1)
Technical Article (273)
Diary (125)
Book (2)
Music (176)
DSP (19)
Tmp.Box (5)
Hardware (7)
Idea (60)
마이크로소프트웨어 (7)

달력

«   2010/09   »
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30