mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
v: forbid function parameter names, shadowing imported module names (#17210)
This commit is contained in:
@ -411,14 +411,14 @@ pub fn (mut rng PRNG) exponential(lambda f64) f64 {
|
||||
// optional and the entire array is shuffled by default. Leave the end as 0 to
|
||||
// shuffle all elements until the end.
|
||||
[direct_array_access]
|
||||
pub fn (mut rng PRNG) shuffle[T](mut a []T, config config.ShuffleConfigStruct) ! {
|
||||
config.validate_for(a)!
|
||||
new_end := if config.end == 0 { a.len } else { config.end }
|
||||
pub fn (mut rng PRNG) shuffle[T](mut a []T, config_ config.ShuffleConfigStruct) ! {
|
||||
config_.validate_for(a)!
|
||||
new_end := if config_.end == 0 { a.len } else { config_.end }
|
||||
|
||||
// We implement the Fisher-Yates shuffle:
|
||||
// https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm
|
||||
|
||||
for i in config.start .. new_end - 2 {
|
||||
for i in config_.start .. new_end - 2 {
|
||||
x := rng.int_in_range(i, new_end) or { i }
|
||||
// swap
|
||||
a_i := a[i]
|
||||
@ -429,9 +429,9 @@ pub fn (mut rng PRNG) shuffle[T](mut a []T, config config.ShuffleConfigStruct) !
|
||||
|
||||
// shuffle_clone returns a random permutation of the elements in `a`.
|
||||
// The permutation is done on a fresh clone of `a`, so `a` remains unchanged.
|
||||
pub fn (mut rng PRNG) shuffle_clone[T](a []T, config config.ShuffleConfigStruct) ![]T {
|
||||
pub fn (mut rng PRNG) shuffle_clone[T](a []T, config_ config.ShuffleConfigStruct) ![]T {
|
||||
mut res := a.clone()
|
||||
rng.shuffle[T](mut res, config)!
|
||||
rng.shuffle[T](mut res, config_)!
|
||||
return res
|
||||
}
|
||||
|
||||
@ -475,10 +475,10 @@ __global default_rng &PRNG
|
||||
|
||||
// new_default returns a new instance of the default RNG. If the seed is not provided, the current time will be used to seed the instance.
|
||||
[manualfree]
|
||||
pub fn new_default(config config.PRNGConfigStruct) &PRNG {
|
||||
pub fn new_default(config_ config.PRNGConfigStruct) &PRNG {
|
||||
mut rng := &wyrand.WyRandRNG{}
|
||||
rng.seed(config.seed_)
|
||||
unsafe { config.seed_.free() }
|
||||
rng.seed(config_.seed_)
|
||||
unsafe { config_.seed_.free() }
|
||||
return &PRNG(rng)
|
||||
}
|
||||
|
||||
@ -680,14 +680,14 @@ pub fn ascii(len int) string {
|
||||
// shuffle randomly permutates the elements in `a`. The range for shuffling is
|
||||
// optional and the entire array is shuffled by default. Leave the end as 0 to
|
||||
// shuffle all elements until the end.
|
||||
pub fn shuffle[T](mut a []T, config config.ShuffleConfigStruct) ! {
|
||||
default_rng.shuffle[T](mut a, config)!
|
||||
pub fn shuffle[T](mut a []T, config_ config.ShuffleConfigStruct) ! {
|
||||
default_rng.shuffle[T](mut a, config_)!
|
||||
}
|
||||
|
||||
// shuffle_clone returns a random permutation of the elements in `a`.
|
||||
// The permutation is done on a fresh clone of `a`, so `a` remains unchanged.
|
||||
pub fn shuffle_clone[T](a []T, config config.ShuffleConfigStruct) ![]T {
|
||||
return default_rng.shuffle_clone[T](a, config)
|
||||
pub fn shuffle_clone[T](a []T, config_ config.ShuffleConfigStruct) ![]T {
|
||||
return default_rng.shuffle_clone[T](a, config_)
|
||||
}
|
||||
|
||||
// choose samples k elements from the array without replacement.
|
||||
@ -716,13 +716,13 @@ pub fn bernoulli(p f64) !bool {
|
||||
|
||||
// normal returns a normally distributed pseudorandom f64 in range `[0, 1)`.
|
||||
// NOTE: Use normal_pair() instead if you're generating a lot of normal variates.
|
||||
pub fn normal(conf config.NormalConfigStruct) !f64 {
|
||||
return default_rng.normal(conf)
|
||||
pub fn normal(config_ config.NormalConfigStruct) !f64 {
|
||||
return default_rng.normal(config_)
|
||||
}
|
||||
|
||||
// normal_pair returns a pair of normally distributed pseudorandom f64 in range `[0, 1)`.
|
||||
pub fn normal_pair(conf config.NormalConfigStruct) !(f64, f64) {
|
||||
return default_rng.normal_pair(conf)
|
||||
pub fn normal_pair(config_ config.NormalConfigStruct) !(f64, f64) {
|
||||
return default_rng.normal_pair(config_)
|
||||
}
|
||||
|
||||
// binomial returns the number of successful trials out of n when the
|
||||
|
@ -29,9 +29,9 @@ const (
|
||||
u64_iter_count = calculate_iterations_for(64)
|
||||
)
|
||||
|
||||
fn calculate_iterations_for(bits int) int {
|
||||
base := bits / sys.rand_bitsize
|
||||
extra := if bits % sys.rand_bitsize == 0 { 0 } else { 1 }
|
||||
fn calculate_iterations_for(bits_ int) int {
|
||||
base := bits_ / sys.rand_bitsize
|
||||
extra := if bits_ % sys.rand_bitsize == 0 { 0 } else { 1 }
|
||||
return base + extra
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user