diff options
| author | Sean Dewar <seandewar@users.noreply.github.com> | 2022-01-09 23:53:55 +0000 |
|---|---|---|
| committer | Sean Dewar <seandewar@users.noreply.github.com> | 2022-02-05 14:00:35 +0000 |
| commit | f6a0d5498b5f0d62e10f7ba891bc6ea5e20dad69 (patch) | |
| tree | 0ac5ea1ed298c284653bc800bd1d630bd36912f1 /src/nvim/testdir/test_random.vim | |
| parent | 22f0725aac300ed9b249f995df7889f6c203d1e0 (diff) | |
| download | rneovim-f6a0d5498b5f0d62e10f7ba891bc6ea5e20dad69.tar.gz rneovim-f6a0d5498b5f0d62e10f7ba891bc6ea5e20dad69.tar.bz2 rneovim-f6a0d5498b5f0d62e10f7ba891bc6ea5e20dad69.zip | |
vim-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
https://github.com/vim/vim/commit/07e4a197953d12902fb97beb48830a5323a52280
Use os_open and os_close.
time_settime is N/A, so some parts of the test are disabled.
There's maybe a very, very, very, very small chance the /dev/urandom test fails,
but it shouldn't matter. :P
Diffstat (limited to 'src/nvim/testdir/test_random.vim')
| -rw-r--r-- | src/nvim/testdir/test_random.vim | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/nvim/testdir/test_random.vim b/src/nvim/testdir/test_random.vim index bde034a96c..46091836d4 100644 --- a/src/nvim/testdir/test_random.vim +++ b/src/nvim/testdir/test_random.vim @@ -11,10 +11,16 @@ func Test_Rand() " Nvim does not support test_settime " call test_settime(12341234) - " let s = srand() - " call assert_equal(s, srand()) - " call test_settime(12341235) - " call assert_notequal(s, srand()) + let 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() @@ -26,6 +32,8 @@ 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 " vim: shiftwidth=2 sts=2 expandtab |