summaryrefslogtreecommitdiff
path: root/lib/std/test/rand.myr
blob: 48e2442b60ab3e32d0c590d9468eaa48385b31b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use std

const main = {
	var v32, t32 : int32
	var vu64, tu64 : uint64
	var allsame

	/* basic int32 */
	allsame = true
	v32 = std.rand(0, 666)
	for var i = 0; i < 128; i++
		t32 = std.rand(0, 666)
		std.assert(t32 >= 0 && t32 < 666, "value {} is out of range [0, 666)\n", t32)
		if t32 != v32
			allsame = false
		;;
	;;
	std.assert(!allsame, "all values generated were identical.\n")


	/* negative range */
	allsame = true
	v32 = std.rand(-888, -111)
	for var i = 0; i < 128; i++
		t32 = std.rand(-888, -111)
		std.assert(t32 >= -888 && t32 < -111, "value {} is out of range [-888, -111)\n", t32)
		if t32 != v32
			allsame = false
		;;
	;;
	std.assert(!allsame, "all values generated were identical.\n")


	/* basic uint64 */
	allsame = true
	vu64 = std.rand(0, 88)
	for var i = 0; i < 128; i++
		tu64 = std.rand(0, 88)
		std.assert(tu64 >= 0 && tu64 < 666, "value {} is out of range [0, 88)\n", tu64)
		if tu64 != vu64
			allsame = false
		;;
	;;
	std.assert(!allsame, "all values generated were identical.\n")
}