mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
js: fix rand
build, properly use key values on map, add rand.string
(#12020)
This commit is contained in:
17
vlib/rand/rand.js.v
Normal file
17
vlib/rand/rand.js.v
Normal file
@ -0,0 +1,17 @@
|
||||
module rand
|
||||
|
||||
// init initializes the default RNG.
|
||||
fn init() {
|
||||
default_rng = new_default()
|
||||
}
|
||||
|
||||
pub fn string(len int) string {
|
||||
result := ''
|
||||
#
|
||||
#const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
#const charactersLength = characters.length;
|
||||
#for (let i = 0;i < len.val;i++)
|
||||
#result.str += characters.charAt(Math.random() * charactersLength);
|
||||
|
||||
return result
|
||||
}
|
Reference in New Issue
Block a user