Beispiel #1
0
// Alloc creates a new random number generator and returs
// it as a RngState object.
// XXX: using SetFinalizer to release the generator doesn't work
// properly since the go runtime destroys the object prematurely.
func Rng_alloc(rngType RngType) RngState {
	state := RngState{C.gsl_rng_alloc(rngType.rng)}

	// make sure we get rid of any memory associated with the
	// rng within gsl
	//runtime.SetFinalizer(&state,
	//  func(rng *RngState) { C.gsl_rng_free(rng.state) })
	return state
}
Beispiel #2
0
// New returns a new RNG of type r
func New(r RNGType) (*RNG, error) {
	ret := new(RNG)
	rtype, err := convertRNGType(r)
	if err != nil {
		return nil, err
	}
	ret.rng = C.gsl_rng_alloc(rtype)
	return ret, nil
}
Beispiel #3
0
func RngAlloc(t *GslRngType) *GslRng {
	_ref := C.gsl_rng_alloc((*C.gsl_rng_type)(unsafe.Pointer(t.Ptr())))
	_result := &GslRng{}
	gogsl.InitializeGslReference(_result, uintptr(unsafe.Pointer(_ref)))
	return _result
}
Beispiel #4
0
func newRandomGenerator(i int) *C.gsl_rng {
	var r *C.gsl_rng
	types := []*C.gsl_rng_type{
		C.gsl_rng_borosh13,
		C.gsl_rng_cmrg,
		C.gsl_rng_coveyou,
		C.gsl_rng_fishman18,
		C.gsl_rng_fishman20,
		C.gsl_rng_fishman2x,
		C.gsl_rng_gfsr4,
		C.gsl_rng_knuthran,
		C.gsl_rng_knuthran2,
		C.gsl_rng_knuthran2002,
		C.gsl_rng_lecuyer21,
		C.gsl_rng_minstd,
		C.gsl_rng_mrg,
		C.gsl_rng_mt19937,
		C.gsl_rng_mt19937_1999,
		C.gsl_rng_mt19937_1998,
		C.gsl_rng_r250,
		C.gsl_rng_ran0,
		C.gsl_rng_ran1,
		C.gsl_rng_ran2,
		C.gsl_rng_ran3,
		C.gsl_rng_rand,
		C.gsl_rng_rand48,
		C.gsl_rng_random128_bsd,
		C.gsl_rng_random128_glibc2,
		C.gsl_rng_random128_libc5,
		C.gsl_rng_random256_bsd,
		C.gsl_rng_random256_glibc2,
		C.gsl_rng_random256_libc5,
		C.gsl_rng_random32_bsd,
		C.gsl_rng_random32_glibc2,
		C.gsl_rng_random32_libc5,
		C.gsl_rng_random64_bsd,
		C.gsl_rng_random64_glibc2,
		C.gsl_rng_random64_libc5,
		C.gsl_rng_random8_bsd,
		C.gsl_rng_random8_glibc2,
		C.gsl_rng_random8_libc5,
		C.gsl_rng_random_bsd,
		C.gsl_rng_random_glibc2,
		C.gsl_rng_random_libc5,
		C.gsl_rng_randu,
		C.gsl_rng_ranf,
		C.gsl_rng_ranlux,
		C.gsl_rng_ranlux389,
		C.gsl_rng_ranlxd1,
		C.gsl_rng_ranlxd2,
		C.gsl_rng_ranlxs0,
		C.gsl_rng_ranlxs1,
		C.gsl_rng_ranlxs2,
		C.gsl_rng_ranmar,
		C.gsl_rng_slatec,
		C.gsl_rng_taus,
		C.gsl_rng_taus2,
		C.gsl_rng_taus113,
		C.gsl_rng_transputer,
		C.gsl_rng_tt800,
		C.gsl_rng_uni,
		C.gsl_rng_uni32,
		C.gsl_rng_vax,
		C.gsl_rng_waterman14,
		C.gsl_rng_zuf,
	}
	if i >= len(types) {
		panic("Can not find gsl rand generator!")
	}
	r = C.gsl_rng_alloc(types[i])
	return r
}