diff options
| author | jdhao <jdhao@hotmail.com> | 2022-08-26 18:44:11 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-26 18:44:11 +0800 |
| commit | fb9a0bb2ddb689066e6ba1a827f2b1b27fe672ca (patch) | |
| tree | 9e7c39d21c30a163dd8dd6aeb23d036c201b3df5 /lua/utils.lua | |
| parent | 6539e72a5d36c308f859a30a97a52deb22f16090 (diff) | |
| parent | 59525c5577abf54a28882961b53cbf5e4dacf584 (diff) | |
Merge pull request #78 from jdhao/theme
refactor: theme.vim --> theme.lua
Diffstat (limited to 'lua/utils.lua')
| -rw-r--r-- | lua/utils.lua | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lua/utils.lua b/lua/utils.lua index 14cc7c2..c2bb85f 100644 --- a/lua/utils.lua +++ b/lua/utils.lua @@ -31,4 +31,30 @@ function M.get_nvim_version() return nvim_ver_str end + +--- Generate random integers in the range [Low, High], inclusive, +--- adapted from https://stackoverflow.com/a/12739441/6064933 +--- @low: the lower value for this range +--- @high: the upper value for this range +function M.rand_int(low, high) + -- Use lua to generate random int, see also: https://stackoverflow.com/a/20157671/6064933 + math.randomseed(os.time()) + + return math.random(low, high) +end + +--- Select a random element from a sequence/list. +--- @seq: the sequence to choose an element +function M.rand_element(seq) + local idx = M.rand_int(1, #seq) + + return seq[idx] +end + +function M.add_pack(name) + local status, error = pcall(vim.cmd, "packadd " .. name) + + return status +end + return M |
