.\" -*- coding: UTF-8 -*- '\" t .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) .\" .\" SPDX-License-Identifier: Linux-man-pages-copyleft .\" .\" References consulted: .\" Linux libc source code .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991) .\" 386BSD man pages .\" Modified Sun Mar 28 00:25:51 1993, David Metcalfe .\" Modified Sat Jul 24 18:13:39 1993 by Rik Faith (faith@cs.unc.edu) .\" Modified Sun Aug 20 21:47:07 2000, aeb .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH random 3 "20 lipca 2023 r." "Linux man\-pages 6.05.01" .SH NAZWA random, srandom, initstate, setstate \- generator liczb losowych .SH BIBLIOTEKA Standardowa biblioteka C (\fIlibc\fP, \fI\-lc\fP) .SH SKŁADNIA .nf \fB#include \fP .PP \fBlong random(void);\fP \fBvoid srandom(unsigned int \fP\fIseed\fP\fB);\fP .PP \fBchar *initstate(unsigned int \fP\fIseed\fP\fB, char \fP\fIstate\fP\fB[.\fP\fIn\fP\fB], size_t \fP\fIn\fP\fB);\fP \fBchar *setstate(char *\fP\fIstate\fP\fB);\fP .fi .PP .RS -4 Wymagane ustawienia makr biblioteki glibc (patrz \fBfeature_test_macros\fP(7)): .RE .PP \fBrandom\fP(), \fBsrandom\fP(), \fBinitstate\fP(), \fBsetstate\fP(): .nf .\" || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED _XOPEN_SOURCE >= 500 || /* glibc >= 2.19: */ _DEFAULT_SOURCE || /* glibc <= 2.19: */ _SVID_SOURCE || _BSD_SOURCE .fi .SH OPIS The \fBrandom\fP() function uses a nonlinear additive feedback random number generator employing a default table of size 31 long integers to return successive pseudo\-random numbers in the range from 0 to 2\[ha]31\ \-\ 1. The period of this random number generator is very large, approximately \fI16\ *\ ((2\[ha]31)\ \-\ 1)\fP. .PP Funkcja \fBsrandom\fP() ustawia swój argument jako wartość początkową dla nowego ciągu pseudolosowych liczb całkowitych zwracanych przez \fBrandom\fP(). Ciągi te są powtarzalne przez wywołanie \fBsrandom\fP() z tą samą wartością początkową. Jeśli nie podano wartości początkowej, funkcja \fBrandom\fP() automatycznie ustawia tę wartość na 1. .PP The \fBinitstate\fP() function allows a state array \fIstate\fP to be initialized for use by \fBrandom\fP(). The size of the state array \fIn\fP is used by \fBinitstate\fP() to decide how sophisticated a random number generator it should use\[em]the larger the state array, the better the random numbers will be. Current "optimal" values for the size of the state array \fIn\fP are 8, 32, 64, 128, and 256 bytes; other amounts will be rounded down to the nearest known amount. Using less than 8 bytes results in an error. \fIseed\fP is the seed for the initialization, which specifies a starting point for the random number sequence, and provides for restarting at the same point. .PP Funkcja \fBsetstate\fP() zmienia tablicę stanów wykorzystywaną przez funkcję \fBrandom\fP(). Tablica stanu \fIstate\fP jest używana do generacji liczb losowych aż do następnego wywołania \fBinitstate\fP() lub \fBsetstate\fP(). \fIstate\fP musi być uprzednio zainicjowana za pomocą \fBinitstate\fP() lub być wynikiem wcześniejszego wywołania \fBsetstate\fP(). .SH "WARTOŚĆ ZWRACANA" The \fBrandom\fP() function returns a value between 0 and \fI(2\[ha]31)\ \-\ 1\fP. The \fBsrandom\fP() function returns no value. .PP The \fBinitstate\fP() function returns a pointer to the previous state array. On failure, it returns NULL, and \fIerrno\fP is set to indicate the error. .PP On success, \fBsetstate\fP() returns a pointer to the previous state array. On failure, it returns NULL, and \fIerrno\fP is set to indicate the error. .SH BŁĘDY .TP \fBEINVAL\fP Argument \fIstate\fP przekazany do \fBsetstate\fP() był równy NULL. .TP \fBEINVAL\fP Podano mniejszą niż 8\-bajtową tablicę stanów dla \fBinitstate\fP(). .SH ATRYBUTY Informacje o pojęciach używanych w tym rozdziale można znaleźć w podręczniku \fBattributes\fP(7). .TS allbox; lbx lb lb l l l. Interfejs Atrybut Wartość T{ .na .nh \fBrandom\fP(), \fBsrandom\fP(), \fBinitstate\fP(), \fBsetstate\fP() T} Bezpieczeństwo wątkowe MT\-bezpieczne .TE .sp 1 .SH STANDARDY POSIX.1\-2008. .SH HISTORIA POSIX.1\-2001, 4.3BSD. .SH UWAGI Generowanie liczb pseudolosowych jest złożonym tematem. "\fINumerical Recipes in C: The Art of Scientific Computing\fP" (William H.\& Press, Brian P.\& Flannery, Saul A.\& Teukolsky, William T.\& Vetterling; New York: Cambridge University Press, 2007, wydanie 3.) w rozdziale 7 ("Random Numbers") zawiera wybitną dyskusję o praktycznych problemach generowania liczb pseudolosowych. .PP Bardziej teoretyczną dyskusję, także zawierającą szczegółowy opis wielu praktycznych problemów można znaleźć w rozdziale 3. ("Random Numbers") drugiego tomu ("Seminumerical Algorithms") książki Donalda E.\& Knutha "\fIThe Art of Computer Programming\fP"; wydanie drugie; Reading, Massachusetts: Addison\-Wesley Publishing Company, 1981. .SH CAVEATS Funkcja \fBrandom\fP() nie powinna być używana w programach wielowątkowych, gdy wymagane jest, by jej zachowanie było powtarzalne. Do tego celu należy użyć \fBrandom_r\fP(3). .SH USTERKI .\" http://sourceware.org/bugzilla/show_bug.cgi?id=15380 Zgodnie z POSIX funkcja \fBinitstate\fP() powinna zwrócić NULL w przypadku błędu. W implementacji glibc w razie błędu ustawiane jest \fIerrno\fP (jak określono w POSIX), ale funkcja nie zwraca NULL. .SH "ZOBACZ TAKŻE" \fBgetrandom\fP(2), \fBdrand48\fP(3), \fBrand\fP(3), \fBrandom_r\fP(3), \fBsrand\fP(3) .PP .SH TŁUMACZENIE Autorami polskiego tłumaczenia niniejszej strony podręcznika są: Andrzej Krzysztofowicz , Robert Luberda i Michał Kułach . .PP Niniejsze tłumaczenie jest wolną dokumentacją. Bliższe informacje o warunkach licencji można uzyskać zapoznając się z .UR https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License w wersji 3 .UE lub nowszej. Nie przyjmuje się ŻADNEJ ODPOWIEDZIALNOŚCI. .PP Błędy w tłumaczeniu strony podręcznika prosimy zgłaszać na adres listy dyskusyjnej .MT manpages-pl-list@lists.sourceforge.net .ME .