本机Vim随机数脚本 [英] Native Vim Random number script

查看:222
本文介绍了本机Vim随机数脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有很多方法可以从外壳程序中获取随机数.但是,我在很少编译的android手机上运行vim.而且,它不一定必须严格随机.关键是,什么是有趣的,简洁的,快速的(即使用vim本机函数),或者是在Vim中获得一系列相当好的随机数的简短方法?

I know that there are various ways to get random numbers, eg, from the shell. However, I'm running vim on an android phone with very little compiled in. Also, it does not have to be rigorously random. The point is, what's an interesting, or concise, or fast (that is, with vim native functions), or short way to get a sequence of reasonably good random numbers in Vim?

推荐答案

尝试类似

function Rand()
    return str2nr(matchstr(reltimestr(reltime()), '\v\.@<=\d+')[1:])
endfunction

.我不知道有比使用某些时间函数更好的选择(它们有两个:reltime()localtime(),但是后者仅每秒更新一次).我宁愿避免使用随机数,也不要使用pyeval('random.randint(1, 10)')(以python import random开头),因为外壳速度很慢,而且我不信任基于时间的解决方案.

. I know no better option then using some of the time functions (there are two of them: reltime() and localtime(), but the latter is updated only each second). I would prefer to either avoid random numbers or use pyeval('random.randint(1, 10)') (preceded by python import random), because shell is slow and I don’t trust time-based solutions.

注意:文档说reltime()返回的项的格式取决于系统,因此我使用的是reltimestr(),而不是对reltime()[1]进行处理,这看起来是否包含纳秒.

Note: documentation says that format of the item returned by reltime() depends on the system, thus I am using reltimestr(), not doing something with reltime()[1] which looks like if it contains nanoseconds.

这篇关于本机Vim随机数脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆