RAND

Section: ������ ���α׷��� �Ŵ��� (3)
Updated: 1995�� 5�� 18��
Index
Return to Main Contents
 

�̸�

rand, srand - random �� ������.  

����

#include <stdlib.h>

int rand(void);

void srand(unsigned int seed);
 

����

rand() �Լ��� 0�� RAND_MAX������ pseudo-random ������ �����Ѵ�.

srand() �Լ��� ���ڸ� rand()�� �����ϴ� pseudo-random ������ ���ο� ���ӵ� ������ ���� ���ڷ� �����Ѵ�. �̵� ���ӵ� ������ ���� seed ������ srand()�� ȣ���Ͽ� �ݺ��ȴ�.

���� � seed ���� �������� �ʴ´ٸ�, rand() �Լ��� �ڵ������� 1 ������ ���ڰ� �ȴ�.  

��ȯ��

rand() �Լ��� 0�� RAND_MAX������ ���� ��ȯ�Ѵ�. srand()�� � ���� ��ȯ���� �ʴ´�.  

����

Linux C ���̺귯���� rand()�� srand() ������ random()�� srandom()ó�� ���� random �� �����⸦ ����Ѵ�. �׷��� lower-order bit ���� higher-order bit�� ��ŭ �����ϴ�. �׷���, ���� rand() �۵�����, lower-order bit���� higher-order bit�麸�� �� �����ߴ�.

Numerical Recipes in C: The Art of Scientific Computing (William H. Press, Brian P. Flannery, Saul A. Teukolsky, William T. Vetterling; New York: Cambridge University Press, 1990 (1st ed, p. 207))��, ������ ���� �ּ��� �ִ�:

"If you want to generate a random integer between 1 and 10, you should always do it by

j=1+(int) (10.0*rand()/(RAND_MAX+1.0));

and never by anything resembling

j=1+((int) (1000000.0*rand()) % 10);

(which uses lower-order bits)."

Random-number ������ �ſ� ������ �����̴�. Numerical Recipes in C å(���� �����)�� Chapter 7 (Random Numbers)���� random-number ������ ���� �������� �Ǹ��� ����� �����Ѵ�.

�� �̷����� ����� ���ϸ�, ���� �ְ� ���� �������� �̽��� �ٷ�� �ִ� Donald E. Knuth�� The Art of Computer Programming, volume 2 (Seminumerical Algorithms), 2nd ���� Chapter 3 (Random Numbers)�� �����ض�.; Reading, Massachusetts: Addison-Wesley Publishing Company, 1981.  

ȣȯ

SVID 3, BSD 4.3, ISO 9899  

���� �׸�

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

����

������ <skyeyes@soback.kornet.net>, 2001�� 3�� 9��


 

Index

�̸�
����
����
��ȯ��
����
ȣȯ
���� �׸�
����

This document was created by man2html, using the manual pages.
Time: 08:07:01 GMT, March 25, 2004