Skip to content

Commit ce58d71

Browse files
committed
feat: add more sample on random
1 parent 38dba6d commit ce58d71

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

content/A-random.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ Di dalam package `math/rand`, ada banyak fungsi untuk generate angka random. Met
7676

7777
Selain itu, ada juga `randomizer.Float32()` yang menghasilkan angka random bertipe `float32`. Ada juga `randomizer.Uint32()` yang menghasilkan angka random bertipe *unsigned* int, dan lainnya.
7878

79+
Contoh penerapan fungsi-fungsi tersebut:
80+
81+
```go
82+
randomizer := rand.New(rand.NewSource(time.Now().UTC().UnixNano()))
83+
fmt.Println("random int:", randomizer.Int())
84+
fmt.Println("random float32:", randomizer.Float32())
85+
fmt.Println("random uint:", randomizer.Uint32())
86+
```
87+
7988
lebih detailnya silakan merujuk ke https://golang.org/pkg/math/rand/
8089

8190
## A.39.5. Angka Random Index Tertentu

0 commit comments

Comments
 (0)