Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jump functions for Xorshift family #38

Open
GregPlowman opened this issue Apr 6, 2018 · 2 comments
Open

Jump functions for Xorshift family #38

GregPlowman opened this issue Apr 6, 2018 · 2 comments

Comments

@GregPlowman
Copy link
Contributor

From http://xoroshiro.di.unimi.it

All generators, being based on linear recurrences, provide jump functions that make it possible to simulate any number of calls to the next-state function in constant time, once a suitable jump polynomial has been computed. We provide ready-made jump functions for a number of calls equal to the square root of the period, to make it easy generating non-overlapping sequences for parallel computations.

Would it be possible to implement jump functions in this package?
This seems like a nice addition for parallel usage.

@sunoru
Copy link
Member

sunoru commented Apr 6, 2018

Thanks for the suggestion. I will look into how to implement jump functions for Xorshift family. Maybe you can also have a look at the advance! functions provided by PCG family.

@kafisatz
Copy link

http://xoshiro.di.unimi.it/xoroshiro128plus.c

how about this (which I have not tested):

function jump!(r::RandomNumbers.Xorshifts.AbstractXoroshiro128) 
	#static const uint64_t JUMP[] = { 0xdf900294d8f554a5, 0x170865df4b3201fc };
	s0 = UInt64(0)
    s1 = UInt64(0)
    for i=0:1
        #for(int i = 0; i < sizeof JUMP / sizeof *JUMP; i++)
        if i==0
            v=0xdf900294d8f554a5
        else 
            v=0x170865df4b3201fc
        end
		for b=0:64-1
            if !(iszero(v & UInt64(1) << b)) #(JUMP[i] & UINT64_C(1) << b)
                #Bitwise exclusive OR and assignment operator.	C ^= 2 is same as C = C ^ 2
				@inbounds s0=xor(s0,r.x) #s0 ^= s[0]; #s0=s0^s[0]
				@inbounds s1=xor(s1,r.y) #s1 ^= s[1]; #s1=s1^s[1]
            end
			RandomNumbers.Xorshifts.xorshift_next(r)
		end
        r.x = s0;
        r.y = s1;
    end
nothing
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants