diff options
| author | jdhao <jdhao@hotmail.com> | 2020-10-19 22:37:08 +0800 |
|---|---|---|
| committer | jdhao <jdhao@hotmail.com> | 2020-10-19 22:37:08 +0800 |
| commit | bb242b7699bb64e25b7497385882aff56fd9c32a (patch) | |
| tree | 95f6001c60ac24d5b551de20fd261a899e4303de /autoload | |
| parent | 63fa99e83b905f910189bdc4b18e948a0040d8be (diff) | |
Use lua to generate random int.
Diffstat (limited to 'autoload')
| -rw-r--r-- | autoload/utils.vim | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/autoload/utils.vim b/autoload/utils.vim index 8ea37d3..34ba3fc 100644 --- a/autoload/utils.vim +++ b/autoload/utils.vim @@ -44,8 +44,9 @@ endfunction " Generate random integers in the range [Low, High] in pure vimscrpt, " adapted from https://stackoverflow.com/a/12739441/6064933 function! utils#RandInt(Low, High) abort - let l:milisec = str2nr(matchstr(reltimestr(reltime()), '\v\.\zs\d+'), 10) - return l:milisec % (a:High - a:Low + 1) + a:Low + " Use lua to generate random int. It is faster. Ref: https://stackoverflow.com/a/20157671/6064933 + call luaeval('math.randomseed(os.time())') + return luaeval(printf('math.random(%s, %s)', a:Low, a:High)) endfunction " Custom fold expr, adapted from https://vi.stackexchange.com/a/9094/15292 |
