Skip to content

Commit

Permalink
dsfmt_rand()
Browse files Browse the repository at this point in the history
  • Loading branch information
Viral Shah committed Jul 2, 2011
1 parent b147f0a commit 4a56c02
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
25 changes: 21 additions & 4 deletions j/random.j
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
libdsfmt = dlopen("libdSFMT")

DSFMT_MEXP = int32(19937)
DSFMT_STATE = Array(Int32, 100000)
DSFMT_POOL_SIZE = 10000
DSFMT_STATE = Array(Int32, 1000)

DSFMT_POOL_SIZE = 4096
DSFMT_POOL = Array(Float64, DSFMT_POOL_SIZE)
DSFMT_POOL_PTR = DSFMT_POOL_SIZE

dsfmt_init() = ccall(dlsym(libdsfmt, :dsfmt_chk_init_gen_rand),
Void, (Ptr{Void}, Uint32, Int32),
DSFMT_STATE, uint32(0), DSFMT_MEXP)

dsfmt_fill_array_open_open(A::Array{Float64}, size::Size) =
dsfmt_fill_array_open_open(A::Array{Float64}, n::Size) =
ccall(dlsym(libdsfmt, :dsfmt_fill_array_open_open),
Void, (Ptr{Void}, Ptr{Float64}, Int32),
DSFMT_STATE, A, size)
DSFMT_STATE, A, n)

function dsfmt_rand()
global DSFMT_POOL_PTR
global DSFMT_POOL_SIZE

if DSFMT_POOL_PTR < DSFMT_POOL_SIZE
DSFMT_POOL_PTR += 1
return DSFMT_POOL[DSFMT_POOL_PTR]
else
dsfmt_fill_array_open_open(DSFMT_POOL, DSFMT_POOL_SIZE)
DSFMT_POOL_PTR = 1
return DSFMT_POOL[1]
end
end

randui64() = boxui64(or_int(zext64(unbox32(randui32())),
shl_int(zext64(unbox32(randui32())),unbox32(32))))
Expand Down
2 changes: 1 addition & 1 deletion j/sysimg.j
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ load("intfuncs.j")
load("floatfuncs.j")
load("math.j")
load("math_libm.j")
load("random.j")
load("random.j"); dsfmt_init();
load("combinatorics.j")
load("linalg.j")
load("linalg_blas.j")
Expand Down

0 comments on commit 4a56c02

Please sign in to comment.