rand: string()
parent
4b0ded0475
commit
c563168d69
|
@ -128,3 +128,15 @@ pub fn f32_in_range(min, max f32) f32 {
|
|||
pub fn f64_in_range(min, max f64) f64 {
|
||||
return default_rng.f64_in_range(min, max)
|
||||
}
|
||||
|
||||
const (
|
||||
chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
)
|
||||
|
||||
pub fn string(len int) string {
|
||||
mut buf := malloc(len)
|
||||
for i in 0..len {
|
||||
buf[i] = chars[intn(chars.len)]
|
||||
}
|
||||
return string(buf, len)
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ module strings
|
|||
|
||||
// random returns a random string with `n` characters
|
||||
/*
|
||||
// TODO
|
||||
pub fn random(n int) string {
|
||||
buf := vmalloc(n)
|
||||
for i in 0..n {
|
||||
|
|
|
@ -167,7 +167,7 @@ Did you forget to add vlib to the path? (Use @vlib for default vlib)')
|
|||
}
|
||||
|
||||
pub fn (v &Builder) get_user_files() []string {
|
||||
if v.pref.path in ['vlib/builtin', 'vlib/strconv'] {
|
||||
if v.pref.path in ['vlib/builtin', 'vlib/strconv', 'vlib/strings', 'vlib/hash'] {
|
||||
// get_builtin_files() has already added the builtin files:
|
||||
v.log('Skipping user files.')
|
||||
return []
|
||||
|
|
|
@ -90,9 +90,16 @@ fn (mut g Gen) gen_fn_decl(it ast.FnDecl) {
|
|||
}
|
||||
} else {
|
||||
if !(it.is_pub || g.pref.is_debug) {
|
||||
// Private functions need to marked as static so that they are not exportable in the
|
||||
// binaries
|
||||
if g.pref.build_mode != .build_module {
|
||||
// if !(g.pref.build_mode == .build_module && g.is_builtin_mod) {
|
||||
// If we are building vlib/builtin, we need all private functions like array_get
|
||||
// to be public, so that all V programs can access them.
|
||||
g.write('static ')
|
||||
g.definitions.write('static ')
|
||||
}
|
||||
}
|
||||
fn_header := if msvc_attrs.len > 0 { '$type_name $msvc_attrs ${name}(' } else { '$type_name ${name}(' }
|
||||
g.definitions.write(fn_header)
|
||||
g.write(fn_header)
|
||||
|
|
Loading…
Reference in New Issue