Man page - random_r(3)

Packages contains this manual

Available languages:

en ja ru ro de

Manual

RANDOM_R

名 前
書 式
説 明
返 り 値
エ ラ ー
属 性
準 拠
バ グ
関 連 項 目
こ の 文 書 に つ い て

名 前

random_r, srandom_r, initstate_r, setstate_r - リ エ ン ト ラ ン ト な 乱 数 生 成 器

書 式

#include <stdlib.h>

int random_r(struct random_data * buf , int32_t * result );

int srandom_r(unsigned int seed , struct random_data * buf );

int initstate_r(unsigned int seed , char * statebuf ,
size_t
statelen , struct random_data * buf );

int setstate_r(char * statebuf , struct random_data * buf );

glibc 向 け の 機 能 検 査 マ ク ロ の 要 件 ( feature_test_macros (7) 参 照 ):

random_r (), srandom_r (), initstate_r (), setstate_r ():

/* glibc 2.19 以 降 : */ _DEFAULT_SOURCE
|| /* glibc 2.19 以 前 : */ _SVID_SOURCE || _BSD_SOURCE

説 明

こ れ ら の 関 数 は 、 random (3) で 説 明 さ れ て い る 関 数 の リ エ ン ト ラ ン ト 版 で 、 等 価 な 機 能 を 持 つ 。 こ れ ら は 、 独 立 し た 再 現 可 能 な 乱 数 列 を 各 ス レ ッ ド が 得 る 必 要 が あ る よ う な マ ル チ ス レ ッ ド プ ロ グ ラ ム で の 使 用 に 適 し て い る 。

The random_r () function is like random (3), except that instead of using state information maintained in a global variable, it uses the state information in the argument pointed to by buf , which must have been previously initialized by initstate_r (). The generated random number is returned in the argument result .

The srandom_r () function is like srandom (3), except that it initializes the seed for the random number generator whose state is maintained in the object pointed to by buf , which must have been previously initialized by initstate_r (), instead of the seed associated with the global state variable.

The initstate_r () function is like initstate (3) except that it initializes the state in the object pointed to by buf , rather than initializing the global state variable. Before calling this function, the buf.state field must be initialized to NULL. The initstate_r () function records a pointer to the statebuf argument inside the structure pointed to by buf . Thus, statebuf should not be deallocated so long as buf is still in use. (So, statebuf should typically be allocated as a static variable, or allocated on the heap using malloc (3) or similar.)

The setstate_r () function is like setstate (3) except that it modifies the state in the object pointed to by buf , rather than modifying the global state variable. state must first have been initialized using initstate_r () or be the result of a previous call of setstate_r ().

返 り 値

こ れ ら の 関 数 は す べ て 、 成 功 す る と 0 を 返 す 。 エ ラ ー の 場 合 、 -1 を 返 し 、 errno に エ ラ ー の 原 因 を 示 す 値 が セ ッ ト さ れ る 。

エ ラ ー

EINVAL

8 バ イ ト よ り 小 さ い 状 態 配 列 が initstate_r () に 指 定 さ れ た 。

EINVAL

setstate_r () の 引 数 statebuf buf が NULL で あ っ た 。

EINVAL

random_r () の 引 数 buf result が NULL で あ っ た 。

属 性

こ の 節 で 使 用 さ れ て い る 用 語 の 説 明 に つ い て は 、 attributes (7) を 参 照 。

Image grohtml-14686-1.png

準 拠

こ れ ら の 関 数 は 非 標 準 で glibc に よ る 拡 張 で あ る 。

バ グ

The initstate_r () interface is confusing. It appears that the random_data type is intended to be opaque, but the implementation requires the user to either initialize the buf.state field to NULL or zero out the entire structure before the call.

関 連 項 目

drand48 (3), rand (3), random (3)

こ の 文 書 に つ い て

こ の man ペ ー ジ は Linux man-pages プ ロ ジ ェ ク ト の リ リ ー ス 5.10 の 一 部 で あ る 。 プ ロ ジ ェ ク ト の 説 明 と バ グ 報 告 に 関 す る 情 報 は https://www.kernel.org/doc/man-pages/ に 書 か れ て い る 。