Mercurial > vim
comparison src/testdir/test_random.vim @ 18701:128662297ddf v8.1.2342
patch 8.1.2342: random number generator in Vim script is slow
Commit: https://github.com/vim/vim/commit/06b0b4bc27077013e9b4b48fd1d9b33e543ccf99
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Nov 25 15:40:55 2019 +0100
patch 8.1.2342: random number generator in Vim script is slow
Problem: Random number generator in Vim script is slow.
Solution: Add rand() and srand(). (Yasuhiro Matsumoto, closes https://github.com/vim/vim/issues/1277)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 25 Nov 2019 15:45:04 +0100 |
parents | |
children | aef98a646d3e |
comparison
equal
deleted
inserted
replaced
18700:975583db60c0 | 18701:128662297ddf |
---|---|
1 " Tests for srand() and rand() | |
2 | |
3 func Test_Rand() | |
4 let r = srand(123456789) | |
5 call assert_equal([123456789, 362436069, 521288629, 88675123], r) | |
6 call assert_equal(3701687786, rand(r)) | |
7 call assert_equal(458299110, rand(r)) | |
8 call assert_equal(2500872618, rand(r)) | |
9 call assert_equal(3633119408, rand(r)) | |
10 call assert_equal(516391518, rand(r)) | |
11 | |
12 call test_settime(12341234) | |
13 let s = srand() | |
14 call assert_equal(s, srand()) | |
15 call test_settime(12341235) | |
16 call assert_notequal(s, srand()) | |
17 | |
18 call srand() | |
19 let v = rand() | |
20 call assert_notequal(v, rand()) | |
21 | |
22 call assert_fails('echo srand([1])', 'E745:') | |
23 call assert_fails('echo rand([1, 2, 3])', 'E475:') | |
24 call assert_fails('echo rand([[1], 2, 3, 4])', 'E475:') | |
25 call assert_fails('echo rand([1, [2], 3, 4])', 'E475:') | |
26 call assert_fails('echo rand([1, 2, [3], 4])', 'E475:') | |
27 call assert_fails('echo rand([1, 2, 3, [4]])', 'E475:') | |
28 endfunc |