forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdSFMT.jl
69 lines (56 loc) · 1.99 KB
/
dSFMT.jl
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
module dSFMT
export DSFMT_state, dsfmt_get_min_array_size, dsfmt_get_idstring,
dsfmt_init_gen_rand, dsfmt_init_by_array,
dsfmt_fill_array_close_open!, dsfmt_fill_array_close1_open2!,
win32_SystemFunction036!
type DSFMT_state
val::Vector{Int32}
DSFMT_state() = new(Array(Int32, 770))
end
function dsfmt_get_idstring()
idstring = ccall((:dsfmt_get_idstring,:libdSFMT),
Ptr{UInt8},
())
return bytestring(idstring)
end
function dsfmt_get_min_array_size()
min_array_size = ccall((:dsfmt_get_min_array_size,:libdSFMT),
Int32,
())
end
const dsfmt_min_array_size = dsfmt_get_min_array_size()
function dsfmt_init_gen_rand(s::DSFMT_state, seed::UInt32)
ccall((:dsfmt_init_gen_rand,:libdSFMT),
Void,
(Ptr{Void}, UInt32,),
s.val, seed)
end
function dsfmt_init_by_array(s::DSFMT_state, seed::Vector{UInt32})
ccall((:dsfmt_init_by_array,:libdSFMT),
Void,
(Ptr{Void}, Ptr{UInt32}, Int32),
s.val, seed, length(seed))
end
# precondition for dsfmt_fill_array_*:
# the underlying C array must be 16-byte aligned, which is the case for "Array"
function dsfmt_fill_array_close1_open2!(s::DSFMT_state, A::Array{Float64}, n::Int)
@assert dsfmt_min_array_size <= n <= length(A) && iseven(n)
ccall((:dsfmt_fill_array_close1_open2,:libdSFMT),
Void,
(Ptr{Void}, Ptr{Float64}, Int),
s.val, A, n)
end
function dsfmt_fill_array_close_open!(s::DSFMT_state, A::Array{Float64}, n::Int)
@assert dsfmt_min_array_size <= n <= length(A) && iseven(n)
ccall((:dsfmt_fill_array_close_open,:libdSFMT),
Void,
(Ptr{Void}, Ptr{Float64}, Int),
s.val, A, n)
end
## Windows entropy
@windows_only begin
function win32_SystemFunction036!(a::Array{UInt32})
ccall((:SystemFunction036,:Advapi32),stdcall,UInt8,(Ptr{Void},UInt32),a,length(a)*sizeof(eltype(a)))
end
end
end # module