当前位置: 首页>>代码示例>>Golang>>正文


Golang Rand.Int63方法代码示例

本文整理汇总了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
}
开发者ID:voidException,项目名称:golucene,代码行数:29,代码来源:mockDirectoryWrapper.go

示例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, "")
}
开发者ID:rwcarlsen,项目名称:ql,代码行数:7,代码来源:all_test.go

示例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
}
开发者ID:voidException,项目名称:golucene,代码行数:8,代码来源:random.go

示例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
		}
	}
}
开发者ID:docker,项目名称:golem,代码行数:9,代码来源:helpers.go

示例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(),
	}
}
开发者ID:zombiezen,项目名称:go-capnproto2,代码行数:10,代码来源:bench_test.go

示例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)
			}
		}
	}
}
开发者ID:voronoipotato,项目名称:ilium,代码行数:55,代码来源:particle_tracing_renderer.go

示例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
}
开发者ID:JamManolo,项目名称:cavemode,代码行数:11,代码来源:refUtils.go

示例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
	}
}
开发者ID:gauravrmazra,项目名称:incubator-htrace,代码行数:12,代码来源:random.go

示例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,
	}
}
开发者ID:kiskovacs,项目名称:golucene,代码行数:14,代码来源:mockAnalyzer.go

示例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
}
开发者ID:bszcz,项目名称:mt19937_64,代码行数:15,代码来源:mt19937_64_concurrency.go

示例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()
}
开发者ID:dgryski,项目名称:go-crandsrc,代码行数:13,代码来源:crandsrc_test.go

示例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)
}
开发者ID:MaxHalford,项目名称:gago,代码行数:16,代码来源:util.go

示例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)
}
开发者ID:ZhuHangpeng,项目名称:mig,代码行数:46,代码来源:integration_test.go

示例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
}
开发者ID:quasemsm,项目名称:rphash-golang,代码行数:17,代码来源:fjlt.go

示例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))
	}
}
开发者ID:jmptrader,项目名称:cockroach,代码行数:47,代码来源:testutils.go


注:本文中的math/rand.Rand.Int63方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。