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-4eefef07ab1c136f901d816822c79336fa89336d.tar.gz lua-4eefef07ab1c136f901d816822c79336fa89336d.tar.bz2 lua-4eefef07ab1c136f901d816822c79336fa89336d.zip | |
'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 | |||
| 815 | -- low-level!! For the current implementation of random in Lua, | 815 | -- low-level!! For the current implementation of random in Lua, |
| 816 | -- the first call after seed 1007 should return 0x7a7040a5a323c9d6 | 816 | -- the first call after seed 1007 should return 0x7a7040a5a323c9d6 |
| 817 | do | 817 | do |
| 818 | -- all computations assume at most 32-bit integers | 818 | -- all computations should work with 32-bit integers |
| 819 | local <const> h = 0x7a7040a5 -- higher half | 819 | local <const> h = 0x7a7040a5 -- higher half |
| 820 | local <const> l = 0xa323c9d6 -- lower half | 820 | local <const> l = 0xa323c9d6 -- lower half |
| 821 | 821 | ||
| @@ -840,7 +840,14 @@ do | |||
| 840 | assert(rand * 2^floatbits == res) | 840 | assert(rand * 2^floatbits == res) |
| 841 | end | 841 | end |
| 842 | 842 | ||
| 843 | math.randomseed() | 843 | do |
| 844 | -- testing return of 'randomseed' | ||
| 845 | local <const> x, <const> y = math.randomseed() | ||
| 846 | local res = math.random(0) | ||
| 847 | math.randomseed(x, y) -- should repeat the state | ||
| 848 | assert(math.random(0) == res) | ||
| 849 | -- keep the random seed for following tests | ||
| 850 | end | ||
| 844 | 851 | ||
| 845 | do -- test random for floats | 852 | do -- test random for floats |
| 846 | local randbits = math.min(floatbits, 64) -- at most 64 random bits | 853 | local randbits = math.min(floatbits, 64) -- at most 64 random bits |
