Files
2025-10-25 03:02:53 +03:00

54 lines
1.6 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[c.math.rand]
# 29 Numerics library [[numerics]](./#numerics)
## 29.5 Random number generation [[rand]](rand#c.math.rand)
### 29.5.10 Low-quality random number generation [c.math.rand]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6923)
[*Note [1](#note-1)*:
The header [<cstdlib>](cstdlib.syn#header:%3ccstdlib%3e "17.2.2Header <cstdlib> synopsis[cstdlib.syn]") declares the functions described in this subclause[.](#1.sentence-1)
— *end note*]
[🔗](#lib:rand)
`int rand();
void srand(unsigned int seed);
`
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6937)
*Effects*: Therand and srand functions have the semantics specified in the C standard library[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L6943)
*Remarks*: The implementation
may specify that particular library functions may callrand[.](#3.sentence-1)
It is implementation-defined
whether the rand function
may introduce data races ([[res.on.data.races]](res.on.data.races "16.4.6.10Data race avoidance"))[.](#3.sentence-2)
[*Note [2](#note-2)*:
The other random
number generation facilities in this document ([[rand]](rand "29.5Random number generation")) are often preferable
to rand, because rand's underlying algorithm is unspecified[.](#3.sentence-3)
Use of rand therefore continues to be non-portable, with unpredictable
and oft-questionable quality and performance[.](#3.sentence-4)
— *end note*]
See also: ISO/IEC 9899:2024, 7.22.2