-
Notifications
You must be signed in to change notification settings - Fork 0
/
11.RandomNumber.go
54 lines (45 loc) · 1.11 KB
/
11.RandomNumber.go
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
46
47
48
49
50
51
52
53
54
package main
import (
"fmt"
"math/rand"
"time"
)
func main(){
RandomIntWithOutSeed()
RandomInt()
RandomIntn()
RandomFloatWithOutSeed()
RandomFloar64()
RandomPerm()// generate a list of random int number
}
func RandomIntWithOutSeed(){
s:= rand.Int()
fmt.Printf("## Random Integer without Seed \n{rand.Int()} : %d \n\n",s)
}
func RandomInt(){
rand.Seed(time.Now().UnixNano())
s:= rand.Int()
fmt.Printf("## Random Integer with Seed \n{rand.Int()} : %d \n\n",s)
}
func RandomIntn(){
rand.Seed(time.Now().UnixNano())
min:=10
max:=20
//s:= rand.Intn(100)
s:= rand.Intn(max-min)+min
fmt.Printf("## Random Integer with Seed with Number Range\n{rand.Intn(max-min)+min} : %d\n\n",s)
}
func RandomFloatWithOutSeed(){
s:=rand.Float64()
fmt.Printf("## Random Float without Seed \n{rand.Float64()} : %f\n\n",s)
}
func RandomFloar64(){
rand.Seed(time.Now().UnixNano())
s:=rand.Float64()
fmt.Printf("## Random Float with Seed \n{rand.Float64()} : %f\n\n",s)
}
func RandomPerm(){
rand.Seed(time.Now().UnixNano())
s:=rand.Perm(10)
fmt.Printf("## Random List of Integer Number \n{rand.Perm(n) : %v\n\n",s)
}