fix usages in vlib

pull/13570/head
Subhomoy Haldar 2022-02-22 19:21:26 +05:30
parent 709bf8f621
commit 5a15facf2f
12 changed files with 34 additions and 34 deletions

View File

@ -36,10 +36,10 @@ fn test_bf_and_not_or_xor() {
mut input2 := bitfield.new(len)
mut i := 0
for i < len {
if rand.intn(2) == 1 {
if rand.intn(2) or { 0 } == 1 {
input1.set_bit(i)
}
if rand.intn(2) == 1 {
if rand.intn(2) or { 0 } == 1 {
input2.set_bit(i)
}
i++
@ -62,7 +62,7 @@ fn test_clone_cmp() {
len := 80
mut input := bitfield.new(len)
for i in 0 .. len {
if rand.intn(2) == 1 {
if rand.intn(2) or { 0 } == 1 {
input.set_bit(i)
}
}
@ -75,7 +75,7 @@ fn test_slice_join() {
len := 80
mut input := bitfield.new(len)
for i in 0 .. len {
if rand.intn(2) == 1 {
if rand.intn(2) or { 0 } == 1 {
input.set_bit(i)
}
}
@ -98,7 +98,7 @@ fn test_pop_count() {
mut count0 := 0
mut input := bitfield.new(len)
for i in 0 .. len {
if rand.intn(2) == 1 {
if rand.intn(2) or { 0 } == 1 {
input.set_bit(i)
count0++
}
@ -113,7 +113,7 @@ fn test_hamming() {
mut input1 := bitfield.new(len)
mut input2 := bitfield.new(len)
for i in 0 .. len {
match rand.intn(4) {
match rand.intn(4) or { 0 } {
0, 1 {
input1.set_bit(i)
count++
@ -152,7 +152,7 @@ fn test_bf_from_str() {
len := 80
mut input := ''
for _ in 0 .. len {
if rand.intn(2) == 1 {
if rand.intn(2) or { 0 } == 1 {
input = input + '1'
} else {
input = input + '0'
@ -172,7 +172,7 @@ fn test_bf_bf2str() {
len := 80
mut input := bitfield.new(len)
for i in 0 .. len {
if rand.intn(2) == 1 {
if rand.intn(2) or { 0 } == 1 {
input.set_bit(i)
}
}
@ -211,7 +211,7 @@ fn test_bf_clear_all() {
len := 80
mut input := bitfield.new(len)
for i in 0 .. len {
if rand.intn(2) == 1 {
if rand.intn(2) or { 0 } == 1 {
input.set_bit(i)
}
}
@ -229,7 +229,7 @@ fn test_bf_reverse() {
len := 80
mut input := bitfield.new(len)
for i in 0 .. len {
if rand.intn(2) == 1 {
if rand.intn(2) or { 0 } == 1 {
input.set_bit(i)
}
}
@ -246,9 +246,9 @@ fn test_bf_reverse() {
fn test_bf_resize() {
len := 80
mut input := bitfield.new(rand.intn(len) + 1)
mut input := bitfield.new(rand.intn(len) or { 0 } + 1)
for _ in 0 .. 100 {
input.resize(rand.intn(len) + 1)
input.resize(rand.intn(len) or { 0 } + 1)
input.set_bit(input.get_size() - 1)
}
assert input.get_bit(input.get_size() - 1) == 1
@ -272,12 +272,12 @@ fn test_bf_pos() {
mut needle := bitfield.new(i)
// fill the needle with random values
for k in 0 .. i {
if rand.intn(2) == 1 {
if rand.intn(2) or { 0 } == 1 {
needle.set_bit(k)
}
}
// make sure the needle contains at least one set bit, selected randomly
r := rand.intn(i)
r := rand.intn(i) or { 0 }
needle.set_bit(r)
// create the haystack, make sure it contains the needle
mut haystack := needle.clone()
@ -323,7 +323,7 @@ fn test_bf_printing() {
len := 80
mut input := bitfield.new(len)
for i in 0 .. len {
if rand.intn(2) == 0 {
if rand.intn(2) or { 0 } == 0 {
input.set_bit(i)
}
}

View File

@ -82,16 +82,16 @@ const (
fn generate_weird_field_element() Element {
return Element{
l0: edwards25519.weird_limbs_52[rand.intn(edwards25519.weird_limbs_52.len)]
l1: edwards25519.weird_limbs_51[rand.intn(edwards25519.weird_limbs_51.len)]
l2: edwards25519.weird_limbs_51[rand.intn(edwards25519.weird_limbs_51.len)]
l3: edwards25519.weird_limbs_51[rand.intn(edwards25519.weird_limbs_51.len)]
l4: edwards25519.weird_limbs_51[rand.intn(edwards25519.weird_limbs_51.len)]
l0: edwards25519.weird_limbs_52[rand.intn(edwards25519.weird_limbs_52.len) or { 0 }]
l1: edwards25519.weird_limbs_51[rand.intn(edwards25519.weird_limbs_51.len) or { 0 }]
l2: edwards25519.weird_limbs_51[rand.intn(edwards25519.weird_limbs_51.len) or { 0 }]
l3: edwards25519.weird_limbs_51[rand.intn(edwards25519.weird_limbs_51.len) or { 0 }]
l4: edwards25519.weird_limbs_51[rand.intn(edwards25519.weird_limbs_51.len) or { 0 }]
}
}
fn (e Element) generate_element() Element {
if rand.intn(2) == 0 {
if rand.intn(2) or { 0 } == 0 {
return generate_weird_field_element()
}
return generate_field_element()

View File

@ -1099,7 +1099,7 @@ fn generate_scalar(size int) ?Scalar {
return reflect.ValueOf(s)
*/
mut s := edwards25519.sc_zero
diceroll := rand.intn(100)
diceroll := rand.intn(100) or {0}
match true {
/*
case diceroll == 0:

View File

@ -75,7 +75,7 @@ pub fn temp_dir(tdo TempFileOptions) ?string {
// * Utility functions
fn random_number() string {
s := (1_000_000_000 + (u32(os.getpid()) + rand.u32n(1_000_000_000))).str()
s := (1_000_000_000 + (u32(os.getpid()) + rand.u32n(1_000_000_000) or { 0 })).str()
return s.substr(1, s.len)
}

View File

@ -142,7 +142,7 @@ fn random_number(length int) Integer {
numbers := '0123456789'
mut stri := ''
for _ in 0 .. length {
i := rand.intn(10)
i := rand.intn(10) or { 0 }
nr := numbers[i]
stri = stri + nr.ascii_str()
}

View File

@ -20,7 +20,7 @@ fn htonl64(payload_len u64) []byte {
// create_masking_key returs a new masking key to use when masking websocket messages
fn create_masking_key() []byte {
mask_bit := byte(rand.intn(255))
mask_bit := rand.byte()
buf := []byte{len: 4, init: `0`}
unsafe { C.memcpy(buf.data, &mask_bit, 4) }
return buf
@ -48,7 +48,7 @@ fn get_nonce(nonce_size int) string {
mut nonce := []byte{len: nonce_size, cap: nonce_size}
alphanum := '0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz'
for i in 0 .. nonce_size {
nonce[i] = alphanum[rand.intn(alphanum.len)]
nonce[i] = alphanum[rand.intn(alphanum.len) or { 0 }]
}
return unsafe { tos(nonce.data, nonce.len) }.clone()
}

View File

@ -21,7 +21,7 @@ fn test_ws_ipv6() {
if should_skip {
return
}
port := 30000 + rand.intn(1024)
port := 30000 + rand.intn(1024) or { 0 }
go start_server(.ip6, port)
time.sleep(500 * time.millisecond)
ws_test(.ip6, 'ws://localhost:$port') or { assert false }
@ -32,7 +32,7 @@ fn test_ws_ipv4() {
if should_skip {
return
}
port := 30000 + rand.intn(1024)
port := 30000 + rand.intn(1024) or { 0 }
go start_server(.ip, port)
time.sleep(500 * time.millisecond)
ws_test(.ip, 'ws://localhost:$port') or { assert false }

View File

@ -9,5 +9,5 @@ const (
// random returns a random time struct in *the past*.
pub fn random() time.Time {
return time.unix(int(rand.i64n(misc.start_time_unix)))
return time.unix(int(rand.i64n(misc.start_time_unix) or { 0 }))
}

View File

@ -1,7 +1,7 @@
import rand
const (
my_random_letter_const = byte(65 + rand.u32n(25))
my_random_letter_const = byte(64) + (rand.byte() % 26)
)
fn test_rand_is_initialized_before_main() {

View File

@ -8,7 +8,7 @@ const (
fn test_generics_with_recursive_generics_fn() {
mut arr := []int{}
for _ in 0 .. gen_len {
arr << rand.intn(gen_max)
arr << rand.intn(gen_max) or { 0 }
}
println('before quick sort whether array is sorted: ${is_sorted<int>(arr)}')
assert !is_sorted<int>(arr)

View File

@ -49,9 +49,9 @@ fn tt(mut sem sync.Semaphore) int {
fn waste_mem(n int, mut sem sync.Semaphore) {
mut m := []voidptr{len: 30}
for j := 0; n < 0 || j < n; j++ {
i := rand.intn(30)
i := rand.intn(30) or { 0 }
m[i] = unsafe { malloc(10000) }
fill := rand.intn(256)
fill := rand.intn(256) or { 0 }
unsafe { C.memset(m[i], fill, 10000) }
if n < 0 && sem.try_wait() {
break

View File

@ -1,7 +1,7 @@
import rand
fn main() {
n := rand.intn(1000)
n := rand.intn(1000) or { 0 }
println(n)
u := rand.uuid_v4()
println(u)