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:
parent
63fa99e83b
commit
bb242b7699
@ -44,8 +44,9 @@ endfunction
|
|||||||
" Generate random integers in the range [Low, High] in pure vimscrpt,
|
" Generate random integers in the range [Low, High] in pure vimscrpt,
|
||||||
" adapted from https://stackoverflow.com/a/12739441/6064933
|
" adapted from https://stackoverflow.com/a/12739441/6064933
|
||||||
function! utils#RandInt(Low, High) abort
|
function! utils#RandInt(Low, High) abort
|
||||||
let l:milisec = str2nr(matchstr(reltimestr(reltime()), '\v\.\zs\d+'), 10)
|
" Use lua to generate random int. It is faster. Ref: https://stackoverflow.com/a/20157671/6064933
|
||||||
return l:milisec % (a:High - a:Low + 1) + a:Low
|
call luaeval('math.randomseed(os.time())')
|
||||||
|
return luaeval(printf('math.random(%s, %s)', a:Low, a:High))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Custom fold expr, adapted from https://vi.stackexchange.com/a/9094/15292
|
" Custom fold expr, adapted from https://vi.stackexchange.com/a/9094/15292
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user