EDIT Since 8.1.2342, Vim introduced a
rand() function as described by @Maxim Kim's answer. I'll keep the question here for historical reference.
I recently needed to generate a random number in vim and this question gave me all the solutions I needed.
But I still have a question: Why is there no built-in function to generate a random number?
I mean the vimscript language provides functions to work with numbers like
min(), the basic operators
+-*/, so what explains that the absence of a
For now I see 2 possible explanations but I wasn't able to validate any of them:
Technical limitations: I know the bad reputation of this language but I don't see what would make it unable to generate a random number.
"Ideological" limitation: The creator of vim script could have decided that the language being made to edit text, doesn't need to generate random numbers and this functionality shouldn't be available to the user. I'm not a Vim guru but I don't understand how including such a function would hurt anything or anyone.
Is there another reason that I couldn't figure out by myself? Could someone enlighten me on this?