Conversation
|
Yasuhiro Matsumoto wrote:
This add Xorshift random generator. In general implementation, srand()
may be called from some plugins in several times. So it need to have
statefull random generator like Xorshift. Below is an usage of
srand().
```vim
:echo srand()
[123456789, 362436069, 521288629, 88675123]
:echo srand(-1)
[1479837050,, 362436069, 521288629, 88675123]
:echo srand(2)
[2, 362436069, 521288629, 88675123]
```
srand return four numbers as list. When expr is not given, the x element of xorshift become 123456789. When negative number is given, x become time(NULL). When positive number is given, x become it given.
Below is an usage of rand()
```vim
let a = srand()
:echo rand(a)
597902826
:echo rand(a)
458295558
:echo rand(a)
1779455562
:echo rand(a)
663552176
:echo rand(a)
507026878
```
What plugin needs a pseudo-random number generator?
…--
hundred-and-one symptoms of being an internet addict:
43. You tell the kids they can't use the computer because "Daddy's got work to
do" and you don't even have a job.
/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
|
|
For example, lorem ipsum generatorhttps://github.com/mattn/emmet-vim This generate example strings. It's useful to confirm html/css with texts like below.
random tips displayhttps://github.com/vim-scripts/Random-Tip-Displayer This is useful to display random tips when vim startup. random colorschemehttps://github.com/mattn/random_colorscheme-vim This may be useful to change of pace, maybe. 😄 gamesfun with vim. 🎮 invador https://github.com/mattn/invader-vim |
|
In other case, useful to generate test data. |
|
Somtimes I want to generate UUID for editing some files, html element id, visual studio solution file for example. I know you probably say I can implement UUIDv1,2,3 and 5. |
|
I don't think the naming rand/srand is good. If you have an idea, please let me know. |
|
+1 for a random generator. Considering there have been patches posted in the past already several times I think it is generally useful |
|
I also needed random number generator a few times, mostly imitating it with |
|
Xorshift use full 32bit and Vim script deson't have unsigned number. So this seems not work on |
|
Do you prefer xorshift() than rand() ? |
|
I could be wrong, but; |
Codecov Report
@@ Coverage Diff @@
## master #1277 +/- ##
==========================================
- Coverage 78.84% 78.83% -0.01%
==========================================
Files 105 105
Lines 142026 142082 +56
==========================================
+ Hits 111976 112017 +41
- Misses 30050 30065 +15
Continue to review full report at Codecov.
|
|
This pull request introduces 1 alert when merging 2520cda into b0e2da2 - view on LGTM.com new alerts:
Comment posted by LGTM.com |
|
It's been a long time in the todo list, and finally bubbled up. To be a bit more descriptive it should be called pseudo-random. |
|
Fixed implementation to be possible to use easily.
|
|
xoshiro128** is better than the Marseglia's xorshift in the point of speed and equidistribution. |
|
@brammool Which do you prefer xorshift or xoshiro128** |
|
Initializing the state with a fixed number is not good because the similar bit pattern produces the similar random sequences. The most famous state initialization algorithm might be MT's init_genrand, but I suggest that using SplitMix32 to fill the state. The example of the proper state initialization is placed in vital.vim. |
|
Initializing the state with a fixed number is not good because the
similar bit pattern produces the similar random sequences.
For example, srand(1) and srand(2) produce similar sequences in spite
of expectation.
The most famous state initialization algorithm might be [MT's init_genrand](http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/CODES/mt19937ar.c), but I suggest that using [SplitMix32](https://github.com/umireon/my-random-stuff/blob/master/xorshift/splitmix32.c) to fill the state.
The example of the proper state initialization is placed in [vital.vim](https://github.com/vim-jp/vital.vim/blob/master/autoload/vital/__vital__/Random/Xor128.vim#L46).
Can you suggest a patch?
…--
Would you care for a drink? I mean, if it were, like,
disabled and you had to look after it?
/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
|
|
OK, I will. |
Problem: Random number generator in Vim script is slow. Solution: Add rand() and srand(). (Yasuhiro Matsumoto, closes vim/vim#1277) vim/vim@06b0b4b vim_time and test_settime is N/A. Add a modeline to test_random.vim.
Problem: Random number generator in Vim script is slow. Solution: Add rand() and srand(). (Yasuhiro Matsumoto, closes vim/vim#1277) vim/vim@06b0b4b Add missing method call usage to eval.txt. vim_time and test_settime is N/A. Add a modeline to test_random.vim.
Problem: Random number generator in Vim script is slow. Solution: Add rand() and srand(). (Yasuhiro Matsumoto, closes vim/vim#1277) vim/vim@06b0b4b Add missing method call usage to eval.txt. vim_time and test_settime is N/A. Add a modeline to test_random.vim.
Problem: Random number generator in Vim script is slow. Solution: Add rand() and srand(). (Yasuhiro Matsumoto, closes vim/vim#1277) vim/vim@06b0b4b Add missing method call usage to eval.txt. vim_time and test_settime is N/A. Add a modeline to test_random.vim. Use typval_T* over listitem_T* vars so we don't need to use TV_LIST_ITEM_TV all over the place...
Problem: Random number generator in Vim script is slow. Solution: Add rand() and srand(). (Yasuhiro Matsumoto, closes vim/vim#1277) vim/vim@06b0b4b Add missing method call usage to eval.txt. vim_time and test_settime is N/A. Add a modeline to test_random.vim. Use typval_T* over listitem_T* vars so we don't need to use TV_LIST_ITEM_TV all over the place... Remove NULL list checks (tv_list_len covers this).
Problem: Random number generator in Vim script is slow. Solution: Add rand() and srand(). (Yasuhiro Matsumoto, closes vim/vim#1277) vim/vim@06b0b4b Add missing method call usage to eval.txt. vim_time and test_settime is N/A. Add a modeline to test_random.vim. Use typval_T* over listitem_T* vars so we don't need to use TV_LIST_ITEM_TV all over the place... Remove NULL list checks (tv_list_len covers this).
Problem: Random number generator in Vim script is slow. Solution: Add rand() and srand(). (Yasuhiro Matsumoto, closes vim/vim#1277) vim/vim@06b0b4b Add missing method call usage to builtin.txt. vim_time and test_settime is N/A. Add a modeline to test_random.vim. Use typval_T* over listitem_T* vars so we don't need to use TV_LIST_ITEM_TV all over the place... Remove NULL list checks (tv_list_len covers this).
Problem: Random number generator in Vim script is slow. Solution: Add rand() and srand(). (Yasuhiro Matsumoto, closes vim/vim#1277) vim/vim@06b0b4b Add missing method call usage to builtin.txt. vim_time and test_settime is N/A. Add a modeline to test_random.vim. Use typval_T* over listitem_T* vars so we don't need to use TV_LIST_ITEM_TV all over the place... Remove NULL list checks (tv_list_len covers this).
Problem: Random number generator in Vim script is slow. Solution: Add rand() and srand(). (Yasuhiro Matsumoto, closes vim/vim#1277) vim/vim@06b0b4b Add missing method call usage to builtin.txt. vim_time and test_settime is N/A. Add a modeline to test_random.vim. Use typval_T* over listitem_T* vars so we don't need to use TV_LIST_ITEM_TV all over the place... Remove NULL list checks (tv_list_len covers this).
This add Xorshift random generator. In general implementation, srand() may be called from some plugins in several times. So it need to have statefull random generator like Xorshift. Below is an usage of srand().
srand return four numbers as list. When expr is not given, the x element of xorshift become 123456789. When negative number is given, x become time(NULL). When positive number is given, x become it given.
Below is an usage of rand()