diff src/testdir/test_random.vim @ 18703:aef98a646d3e v8.1.2343

patch 8.1.2343: using time() for srand() is not very random Commit: https://github.com/vim/vim/commit/07e4a197953d12902fb97beb48830a5323a52280 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Nov 26 12:23:30 2019 +0100 patch 8.1.2343: using time() for srand() is not very random Problem: Using time() for srand() is not very random. Solution: use /dev/urandom if available
author Bram Moolenaar <Bram@vim.org>
date Tue, 26 Nov 2019 12:30:04 +0100
parents 128662297ddf
children 2513e666aa82
line wrap: on
line diff
--- 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