aboutsummaryrefslogtreecommitdiff
path: root/autoload/utils.vim
diff options
context:
space:
mode:
authorjdhao <jdhao@hotmail.com>2020-10-19 22:37:08 +0800
committerjdhao <jdhao@hotmail.com>2020-10-19 22:37:08 +0800
commitbb242b7699bb64e25b7497385882aff56fd9c32a (patch)
tree95f6001c60ac24d5b551de20fd261a899e4303de /autoload/utils.vim
parent63fa99e83b905f910189bdc4b18e948a0040d8be (diff)
Use lua to generate random int.
Diffstat (limited to 'autoload/utils.vim')
-rw-r--r--autoload/utils.vim5
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