Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
- Ada
- C
- C++
- C#
- D
- Dart
- Elixir
- Fortran
- Go
- Go
- Haskell
- JS
- Java
- Kotlin
- Lisp
- Lua
- PHP
- Pascal
- Perl
- Python
- Ruby
- Rust
:random.seed(s)
call random_seed(size = n)
allocate(seed(n))
! ...
call random_seed(put=seed)
seed is an allocatable variable.
System.Random.mkStdGen s
seed (s)
s is impure—it can give different outputs with the same input.
call random_seed (put=s)
math.randomseed(s)
srand($s);
var
SomeInteger: Integer;
Value: double;
begin
...
//initializes the PRNG's seed with a value depensing on system time
Randomize;
Value := random;
...
//Output will be the same eacht time the program runs
RandSeed := SomeInteger;
Value := random;
...
end.
srand($s);
r = Random.new(s)
Don't use system time to seed; not specifying s is far superior. (Docs: If number is omitted, seeds the generator using a source of entropy provided by the operating system, if available (/dev/urandom on Unix systems or the RSA cryptographic provider on Windows), which is then combined with the time, the process id, and a sequence number.)