aboutsummaryrefslogtreecommitdiff
path: root/Tausworthe.R
blob: e4fe35568496b5c523117249565cf8728a799346 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
library(methods)

dyn.load('tausR.so')

TauswortheRNG <- setRefClass('TauswortheRNG',
	fields=list(
		    seed='numeric',
		    state='numeric'
		    ),
	methods=list(
		initialize=function(..., seed=0) {
			seed <<- seed
			tmp <- .Call('R_tausworthe_seed',
			     as.integer(seed))
			state <<- tmp[1:4]
			callSuper(...)
		},
		randi=function() {
			tmp <- .Call('R_tausworthe_rand',
				     as.integer(state))
			state <<- tmp[1:4]
			return(tmp[5])
		},
		rand=function() {
			r <- randi()
			return (r * 2.3283064365387e-10)
		}
		)
	)

taus.seed <- function(seed=0)
{
	t <- TauswortheRNG(seed=seed)
	return(t)
}

taus.rand <- function(t)
{
	return(t$rand())
}

taus.randi <- function(t)
{
	return(t$randi())
}