diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-07-17 16:00:24 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-07-17 16:00:24 -0300 |
| commit | 4eefef07ab1c136f901d816822c79336fa89336d (patch) | |
| tree | ce2232ba8a09287899af1ac07af0c902800bfae6 /testes/math.lua | |
| parent | 9c28ed05c95cb6854d917ac3e3ed7be9ae109480 (diff) | |
| download | lua-github-4eefef07ab1c136f901d816822c79336fa89336d.tar.gz | |
'math.randomseed()' returns the seeds it used
A call to 'math.randomseed()' returns the two components of the seed
it set, so that they can be used to set that same seed again.
Diffstat (limited to 'testes/math.lua')
| -rw-r--r-- | testes/math.lua | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/testes/math.lua b/testes/math.lua index befce12e..0c297e74 100644 --- a/testes/math.lua +++ b/testes/math.lua @@ -815,7 +815,7 @@ end -- low-level!! For the current implementation of random in Lua, -- the first call after seed 1007 should return 0x7a7040a5a323c9d6 do - -- all computations assume at most 32-bit integers + -- all computations should work with 32-bit integers local <const> h = 0x7a7040a5 -- higher half local <const> l = 0xa323c9d6 -- lower half @@ -840,7 +840,14 @@ do assert(rand * 2^floatbits == res) end -math.randomseed() +do + -- testing return of 'randomseed' + local <const> x, <const> y = math.randomseed() + local res = math.random(0) + math.randomseed(x, y) -- should repeat the state + assert(math.random(0) == res) + -- keep the random seed for following tests +end do -- test random for floats local randbits = math.min(floatbits, 64) -- at most 64 random bits |
