I want to randomly pick an item in a array.Like javascript code
words[Math.floor(Math.random() * words.length)]
But I don't know how to generate a number like javascript Math.random() function in vlang. Does anyone know ?
I want to randomly pick an item in a array.Like javascript code
words[Math.floor(Math.random() * words.length)]
But I don't know how to generate a number like javascript Math.random() function in vlang. Does anyone know ?
Per the documentation at rand, you can use the
rand
module and for example, therand.u32n(words.length)
function. Make sure you handle the optional case..