간단하게 3 * 3 에 맞는 것을 배열에 표시하기.
총 9개를 각각 랜덤 모듈을 이용해서 간단하게 배열내에 있는 값으로 배치하기
package main
import (
"fmt"
"math/rand"
)
func main() {
fmt.Println(" random test ")
var a Cube
a.Set(1)
fmt.Println(" level", a.Level)
fmt.Println(" list ", a.List)
a.Set(2)
fmt.Println(" level 2 ", a.Level)
fmt.Println(" list 2 ", a.List)
a.Set(3)
fmt.Println(" level", a.Level)
fmt.Println(" list ", a.List)
}
var Pocket [24]int = [24]int{10, 10, 10, 10,
21, 22, 23, 24,
31, 32, 33, 34,
41, 42, 43, 44,
51, 52, 53, 54,
60, 60, 60, 60}
var Pocket1 [18]int = [18]int{10,
21, 22, 23, 24,
31, 32, 33, 34,
41, 42, 43, 44,
51, 52, 53, 54,
60}
var levelAr [3]int = [3]int{100, 10000, 1000000}
var pocket [3]int = [3]int{24, 18, 18}
type Cube struct {
Level int
List [9]int
}
func (this *Cube) Set(level int) {
this.Level = level
levelCalc(this, level)
}
func levelCalc(this *Cube, level int) {
for i := 0; i < 9; i++ {
any := 0
v := rand.Int()
s := v / levelAr[level-1]
t := v - (s * levelAr[level-1])
fmt.Println(" t ", t)
if t > pocket[level-1] {
any = t % pocket[level-1]
} else {
any = t
}
switch level {
case 1:
this.List[i] = Pocket[any]
case 2:
this.List[i] = Pocket1[any]
case 3:
this.List[i] = Pocket1[any]
}
}
}
댓글
댓글 쓰기