summaryrefslogtreecommitdiff
path: root/src/testdir/test_random.vim
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-11-26 12:23:30 +0100
committerBram Moolenaar <Bram@vim.org>2019-11-26 12:23:30 +0100
commit07e4a197953d12902fb97beb48830a5323a52280 (patch)
tree2606081e24020a6d9985531651099b0fc2aa3381 /src/testdir/test_random.vim
parent06b0b4bc27077013e9b4b48fd1d9b33e543ccf99 (diff)
downloadvim-git-07e4a197953d12902fb97beb48830a5323a52280.tar.gz
patch 8.1.2343: using time() for srand() is not very randomv8.1.2343
Problem: Using time() for srand() is not very random. Solution: use /dev/urandom if available
Diffstat (limited to 'src/testdir/test_random.vim')
-rw-r--r--src/testdir/test_random.vim14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/testdir/test_random.vim b/src/testdir/test_random.vim
index 381475a43..9fe71a98c 100644
--- a/src/testdir/test_random.vim
+++ b/src/testdir/test_random.vim
@@ -11,9 +11,15 @@ func Test_Rand()
call test_settime(12341234)
let s = srand()
- call assert_equal(s, srand())
- call test_settime(12341235)
- call assert_notequal(s, srand())
+ if filereadable('/dev/urandom')
+ " using /dev/urandom
+ call assert_notequal(s, srand())
+ else
+ " using time()
+ call assert_equal(s, srand())
+ call test_settime(12341235)
+ call assert_notequal(s, srand())
+ endif
call srand()
let v = rand()
@@ -25,4 +31,6 @@ func Test_Rand()
call assert_fails('echo rand([1, [2], 3, 4])', 'E475:')
call assert_fails('echo rand([1, 2, [3], 4])', 'E475:')
call assert_fails('echo rand([1, 2, 3, [4]])', 'E475:')
+
+ call test_settime(0)
endfunc