diff options
author | Sean Dewar <seandewar@users.noreply.github.com> | 2022-02-05 15:30:09 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-05 15:30:09 +0000 |
commit | f68d25737fffed76f320ee3100dac9fb396f30f8 (patch) | |
tree | 4e2b4bd5e222ce0f339fda77dd8a1a3cbc3dc5f4 /runtime | |
parent | ef6cedf820f851020816ed02fe9f05993878b780 (diff) | |
parent | 4f7a8991a93ddb1b6ab7cd8a8f21b5197c4612bb (diff) | |
download | rneovim-f68d25737fffed76f320ee3100dac9fb396f30f8.tar.gz rneovim-f68d25737fffed76f320ee3100dac9fb396f30f8.tar.bz2 rneovim-f68d25737fffed76f320ee3100dac9fb396f30f8.zip |
Merge pull request #17020 from seandewar/vim-8.1.2342
vim-patch:8.1.{2342,2343,2356,2357},8.2.0233: `rand` and `srand`
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/doc/builtin.txt | 36 | ||||
-rw-r--r-- | runtime/doc/vim_diff.txt | 1 |
2 files changed, 37 insertions, 0 deletions
diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt index 4153c1c9d8..327b8dc4d9 100644 --- a/runtime/doc/builtin.txt +++ b/runtime/doc/builtin.txt @@ -325,6 +325,7 @@ pumvisible() Number whether popup menu is visible pyeval({expr}) any evaluate |Python| expression py3eval({expr}) any evaluate |python3| expression pyxeval({expr}) any evaluate |python_x| expression +rand([{expr}]) Number get pseudo-random number range({expr} [, {max} [, {stride}]]) List items from {expr} to {max} readdir({dir} [, {expr}]) List file names in {dir} selected by {expr} @@ -441,6 +442,7 @@ spellsuggest({word} [, {max} [, {capital}]]) split({expr} [, {pat} [, {keepempty}]]) List make |List| from {pat} separated {expr} sqrt({expr}) Float square root of {expr} +srand([{expr}]) List get seed for |rand()| stdioopen({dict}) Number open stdio in a headless instance. stdpath({what}) String/List returns the standard path(s) for {what} str2float({expr} [, {quoted}]) Float convert String to Float @@ -5530,6 +5532,23 @@ range({expr} [, {max} [, {stride}]]) *range()* Can also be used as a |method|: > GetExpr()->range() < +rand([{expr}]) *rand()* + Return a pseudo-random Number generated with an xoshiro128** + algorithm using seed {expr}. The returned number is 32 bits, + also on 64 bits systems, for consistency. + {expr} can be initialized by |srand()| and will be updated by + rand(). If {expr} is omitted, an internal seed value is used + and updated. + + Examples: > + :echo rand() + :let seed = srand() + :echo rand(seed) + :echo rand(seed) % 16 " random number 0 - 15 +< + Can also be used as a |method|: > + seed->rand() +< *readdir()* readdir({directory} [, {expr}]) Return a list with file and directory names in {directory}. @@ -7178,6 +7197,23 @@ sqrt({expr}) *sqrt()* Can also be used as a |method|: > Compute()->sqrt() +srand([{expr}]) *srand()* + Initialize seed used by |rand()|: + - If {expr} is not given, seed values are initialized by + reading from /dev/urandom, if possible, or using time(NULL) + a.k.a. epoch time otherwise; this only has second accuracy. + - If {expr} is given it must be a Number. It is used to + initialize the seed values. This is useful for testing or + when a predictable sequence is intended. + + Examples: > + :let seed = srand() + :let seed = srand(userinput) + :echo rand(seed) +< + Can also be used as a |method|: > + userinput->srand() + stdioopen({opts}) *stdioopen()* With |--headless| this opens stdin and stdout as a |channel|. May be called only once. See |channel-stdio|. stderr is not diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt index 7e61eac404..11849632c5 100644 --- a/runtime/doc/vim_diff.txt +++ b/runtime/doc/vim_diff.txt @@ -574,6 +574,7 @@ Test functions: test_scrollbar() test_setmouse() test_settime() + test_srand_seed() TUI: *t_xx* *termcap-options* *t_AB* *t_Sb* *t_vb* *t_SI* |