本文整理汇总了Golang中rand.Rand.Perm方法的典型用法代码示例。如果您正苦于以下问题:Golang Rand.Perm方法的具体用法?Golang Rand.Perm怎么用?Golang Rand.Perm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rand.Rand
的用法示例。
在下文中一共展示了Rand.Perm方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Sample
// Sample returns N random points sampled from a fill with step
// distance between low and hi inclusive. it will return a count > 1
// if the sample size is smaller than N. If n < 1 then return all
// points.
func (f *Fill) Sample(r *rand.Rand, n, low, high int) ([]Location, []int) {
pool := make([]Location, 0, 200)
lo, hi := uint16(low), uint16(high)
for i, depth := range f.Depth {
if depth >= lo && depth <= hi {
pool = append(pool, Location(i))
}
}
if n < 1 {
return pool, nil
}
if len(pool) == 0 {
return nil, nil
}
over := n / len(pool)
perm := r.Perm(len(pool))[0 : n%len(pool)]
if Debug[DBG_Sample] {
log.Printf("Sample: Looking for %d explore points %d-%d, have %d possible", n, low, hi, len(pool))
}
var count []int
if over > 0 {
count = make([]int, len(pool))
for i := range count {
count[i] = over
}
} else {
count = make([]int, len(perm))
}
for i := range perm {
count[i]++
}
if over > 0 {
return pool, count
} else {
pout := make([]Location, len(perm))
for i, pi := range perm {
if Debug[DBG_Sample] {
log.Printf("Sample: adding location %d to output pool", pool[pi])
}
pout[i] = pool[pi]
}
return pout, count
}
return nil, nil
}