本文整理汇总了Golang中math/rand.Rand.Int63方法的典型用法代码示例。如果您正苦于以下问题:Golang Rand.Int63方法的具体用法?Golang Rand.Int63怎么用?Golang Rand.Int63使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类math/rand.Rand
的用法示例。
在下文中一共展示了Rand.Int63方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewMockDirectoryWrapper
func NewMockDirectoryWrapper(random *rand.Rand, delegate store.Directory) *MockDirectoryWrapper {
ans := &MockDirectoryWrapper{
noDeleteOpenFile: true,
preventDoubleWrite: true,
trackDiskUsage: false,
wrapLockFactory: true,
openFilesForWrite: make(map[string]bool),
openLocks: make(map[string]bool),
openLocksLock: &sync.Mutex{},
throttling: THROTTLING_SOMETIMES,
inputCloneCount: 0,
openFileHandles: make(map[io.Closer]error),
failOnCreateOutput: true,
failOnOpenInput: true,
assertNoUnreferencedFilesOnClose: true,
}
ans.BaseDirectoryWrapperImpl = NewBaseDirectoryWrapper(delegate)
ans.Locker = &sync.Mutex{}
// must make a private random since our methods are called from different
// methods; else test failures may not be reproducible from the original
// seed
ans.randomState = rand.New(rand.NewSource(random.Int63()))
ans.throttledOutput = NewThrottledIndexOutput(
MBitsToBytes(40+ans.randomState.Intn(10)), 5+ans.randomState.Int63n(5), nil)
// force wrapping of LockFactory
ans.myLockFactory = newMockLockFactoryWrapper(ans, delegate.LockFactory())
ans.init()
return ans
}
示例2: rnds16
func rnds16(rng *rand.Rand, n int) string {
a := make([]string, n)
for i := range a {
a[i] = fmt.Sprintf("%016x", rng.Int63())
}
return strings.Join(a, "")
}
示例3: NewMockRandomMergePolicy
func NewMockRandomMergePolicy(r *rand.Rand) *MockRandomMergePolicy {
// fork a private random, since we are called unpredicatably from threads:
res := &MockRandomMergePolicy{
random: rand.New(rand.NewSource(r.Int63())),
}
res.MergePolicyImpl = NewDefaultMergePolicyImpl(res)
return res
}
示例4: readRand
func readRand(r *rand.Rand, p []byte) {
for i := 0; i < len(p); i += 7 {
val := r.Int63()
for j := 0; i+j < len(p) && j < 7; j++ {
p[i+j] = byte(val)
val >>= 8
}
}
}
示例5: generateA
func generateA(r *rand.Rand) *A {
return &A{
Name: randString(r, 16),
BirthDay: r.Int63(),
Phone: randString(r, 10),
Siblings: r.Int31n(5),
Spouse: r.Intn(2) == 1,
Money: r.Float64(),
}
}
示例6: Render
func (ptr *ParticleTracingRenderer) Render(
numRenderJobs int, rng *rand.Rand, scene *Scene,
outputDir, outputExt string) {
var combinedLightConfig SampleConfig
for _, light := range scene.Lights {
lightConfig := light.GetSampleConfig()
combinedLightConfig.CombineWith(&lightConfig)
}
var totalSampleCount int
sensors := scene.Aggregate.GetSensors()
for _, sensor := range sensors {
extent := sensor.GetExtent()
totalSampleCount += extent.GetSampleCount()
}
samplesPerJob := (totalSampleCount + numRenderJobs - 1) / numRenderJobs
totalSampleCount = samplesPerJob * numRenderJobs
channelSize := minInt(totalSampleCount, 1024)
recordsCh := make(chan []TracerRecord, channelSize)
for i := 0; i < numRenderJobs; i++ {
workerRng := rand.New(rand.NewSource(rng.Int63()))
go ptr.processSamples(
workerRng, scene, sensors, combinedLightConfig,
samplesPerJob, recordsCh)
}
progressInterval := (totalSampleCount + 99) / 100
for i := 0; i < totalSampleCount; i++ {
records := <-recordsCh
for j := 0; j < len(records); j++ {
records[j].Accumulate()
}
for _, sensor := range sensors {
sensor.RecordAccumulatedLightContributions()
}
if (i+1)%progressInterval == 0 || i+1 == totalSampleCount {
fmt.Printf("Processed %d/%d sample(s)\n",
i+1, totalSampleCount)
}
if ((i + 1) == totalSampleCount) ||
(ptr.emitInterval > 0 && (i+1)%ptr.emitInterval == 0) {
for _, sensor := range sensors {
sensor.EmitSignal(outputDir, outputExt)
}
}
}
}
示例7: generateRandomRefValue
func generateRandomRefValue() string {
var r *rand.Rand
sval := ""
for len(sval) < 16 {
r = rand.New(rand.NewSource(int64(time.Now().UnixNano())))
sval = fmt.Sprintf("%x", r.Int63())
}
return sval
}
示例8: NonZeroRand64
func NonZeroRand64(rnd *rand.Rand) int64 {
for {
r := rnd.Int63()
if r == 0 {
continue
}
if rnd.Intn(1) != 0 {
return -r
}
return r
}
}
示例9: NewMockAnalyzer
// Creates a new MockAnalyzer.
func NewMockAnalyzer(r *rand.Rand, runAutomaton *auto.CharacterRunAutomaton, lowerCase bool, filter *auto.CharacterRunAutomaton) *MockAnalyzer {
return &MockAnalyzer{
AnalyzerImpl: ca.NewAnalyzerWithStrategy(ca.PER_FIELD_REUSE_STRATEGY),
// TODO: this should be solved in a different way; Random should not be shared (!)
random: rand.New(rand.NewSource(r.Int63())),
runAutomaton: runAutomaton,
lowerCase: lowerCase,
filter: filter,
previousMappings: make(map[string]int),
enableChecks: true,
maxTokenLength: DEFAULT_MAX_TOKEN_LENGTH,
}
}
示例10: PrintInt63
// Print random int63 number from "mt19937_64".
// Reset random number generator if "i" is 13.
func PrintInt63(i int, mt *rand.Rand, ch chan bool) {
t := rand.Int() % 1000
time.Sleep(time.Duration(t))
if 13 == i {
mt.Seed(12345)
fmt.Printf("13 : (reset) \n")
} else {
fmt.Printf("%2d : %d \n", i, mt.Int63())
}
ch <- true
}
示例11: ExampleSource
func ExampleSource() {
var r *rand.Rand
// Instead of this
r = rand.New(rand.NewSource(time.Now().UnixNano()))
// Use this...
r = rand.New(Source{})
// and then call this...
r.Int63()
}
示例12: randomString
// Generate a random string of size n.
func randomString(n int, rng *rand.Rand) string {
b := make([]byte, n)
for i, cache, remain := n-1, rng.Int63(), letterIdxMax; i >= 0; {
if remain == 0 {
cache, remain = rng.Int63(), letterIdxMax
}
if idx := int(cache & letterIdxMask); idx < len(letterBytes) {
b[i] = letterBytes[idx]
i--
}
cache >>= letterIdxBits
remain--
}
return string(b)
}
示例13: Generate
func (c Publishing) Generate(r *rand.Rand, _ int) reflect.Value {
var ok bool
var t reflect.Value
p := Publishing{}
//p.DeliveryMode = uint8(r.Intn(3))
//p.Priority = uint8(r.Intn(8))
if r.Intn(2) > 0 {
p.ContentType = "application/octet-stream"
}
if r.Intn(2) > 0 {
p.ContentEncoding = "gzip"
}
if r.Intn(2) > 0 {
p.CorrelationId = fmt.Sprintf("%d", r.Int())
}
if r.Intn(2) > 0 {
p.ReplyTo = fmt.Sprintf("%d", r.Int())
}
if r.Intn(2) > 0 {
p.MessageId = fmt.Sprintf("%d", r.Int())
}
if r.Intn(2) > 0 {
p.Type = fmt.Sprintf("%d", r.Int())
}
if r.Intn(2) > 0 {
p.AppId = fmt.Sprintf("%d", r.Int())
}
if r.Intn(2) > 0 {
p.Timestamp = time.Unix(r.Int63(), r.Int63())
}
if t, ok = quick.Value(reflect.TypeOf(p.Body), r); ok {
p.Body = t.Bytes()
}
return reflect.ValueOf(p)
}
示例14: GenerateD
func GenerateD(d int64, random *rand.Rand) []float64 {
var i, j, l int64
data := make([]float64, d)
for i = 0; i < d; {
l = random.Int63()
for j = 0; j < 32 && i < d; j++ {
if (l & 1) == 1 {
data[i] = 1
} else {
data[i] = -1
}
l = l >> 1
i++
}
}
return data
}
示例15: RandDatum
// RandDatum generates a random Datum of the given type.
// If null is true, the datum can be DNull.
func RandDatum(rng *rand.Rand, typ ColumnType_Kind, null bool) parser.Datum {
if null && rng.Intn(10) == 0 {
return parser.DNull
}
switch typ {
case ColumnType_BOOL:
return parser.MakeDBool(rng.Intn(2) == 1)
case ColumnType_INT:
return parser.NewDInt(parser.DInt(rng.Int63()))
case ColumnType_FLOAT:
return parser.NewDFloat(parser.DFloat(rng.NormFloat64()))
case ColumnType_DECIMAL:
d := &parser.DDecimal{}
d.Dec.SetScale(inf.Scale(rng.Intn(40) - 20))
d.Dec.SetUnscaled(rng.Int63())
return d
case ColumnType_DATE:
return parser.NewDDate(parser.DDate(rng.Intn(10000)))
case ColumnType_TIMESTAMP:
return &parser.DTimestamp{Time: time.Unix(rng.Int63n(1000000), rng.Int63n(1000000))}
case ColumnType_INTERVAL:
return &parser.DInterval{Duration: duration.Duration{Months: rng.Int63n(1000),
Days: rng.Int63n(1000),
Nanos: rng.Int63n(1000000),
}}
case ColumnType_STRING:
// Generate a random ASCII string.
p := make([]byte, rng.Intn(10))
for i := range p {
p[i] = byte(1 + rng.Intn(127))
}
return parser.NewDString(string(p))
case ColumnType_BYTES:
p := make([]byte, rng.Intn(10))
_, _ = rng.Read(p)
return parser.NewDBytes(parser.DBytes(p))
case ColumnType_TIMESTAMPTZ:
return &parser.DTimestampTZ{Time: time.Unix(rng.Int63n(1000000), rng.Int63n(1000000))}
case ColumnType_INT_ARRAY:
// TODO(cuongdo): we don't support for persistence of arrays yet
return parser.DNull
default:
panic(fmt.Sprintf("invalid type %s", typ))
}
}