Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

random - Pseudo-Zufallszahlen erzeugen

&pagelevel(4)&pagelevel

Definition

#include <stdlib.h>

long random(void);

Beschreibung

siehe initstate().

random() erzeugt Pseudo-Zufallszahlen im Bereich von 0 bis 2 31-1.

random() ist nicht threadsicher. Verwenden Sie bei Bedarf die reentrante Funktion rand_r().

Returnwert

Pseudo-Zufallszahl (siehe initstate()).

Beispiel

/* Initialize an array and pass it to initstate. */

static long state1[32] = { 3, 0x9a319039, 0x32d9c024, 0x9b663182, 0x5da1f342, 
0x7449e56b, 0xbeb1dbb0, 0xab5c5918, 0x946554fd, 0x8c2e680f, 0xeb3d799f, 
0xb11ee0b7, 0x2d436b86, 0xda672e2a, 0x1588ca88, 0xe369735d, 0x904f35f7, 
0xd7158fd6, 0x6fa6f051, 0x616e6b96, 0xac94efdc, 0xde3b81e0, 0xdf0a6fb5, 
0xf103bc02, 0x48f340fb, 0x36413f93, 0xc622c298, 0xf5a42ab8, 0x8a88d77b, 
0xf5ad9d0e, 0x8999220b, 0x27fb47b9 };
main()
{ 
unsigned seed;
int n; 
seed = 1; 
n = 128; 
initstate(seed, state1, n); 
setstate(state1); 
printf("%d\0", random());
}

Siehe auch

drand48(), rand(), rand_r(), srand(), stdlib.h .