1
0
mirror of https://github.com/jdhao/nvim-config.git synced 2025-06-08 14:14:33 +02:00

Use lua to generate random int.

This commit is contained in:
jdhao 2020-10-19 22:37:08 +08:00
parent 63fa99e83b
commit bb242b7699

View File

@ -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