xorshift | Implementations of a couple of xorshift PRNGs

 by   grunka Java Version: 1.2 License: MIT

kandi X-RAY | xorshift Summary

kandi X-RAY | xorshift Summary

xorshift is a Java library. xorshift has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has low support. You can download it from GitHub, Maven.

Implementations of a couple of xorshift PRNGs as seen on Wikipedia.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              xorshift has a low active ecosystem.
              It has 1 star(s) with 0 fork(s). There are 1 watchers for this library.
              OutlinedDot
              It had no major release in the last 12 months.
              xorshift has no issues reported. There are no pull requests.
              It has a neutral sentiment in the developer community.
              The latest version of xorshift is 1.2

            kandi-Quality Quality

              xorshift has no bugs reported.

            kandi-Security Security

              xorshift has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.

            kandi-License License

              xorshift is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              xorshift releases are available to install and integrate.
              Deployable package is available in Maven.
              Build file is available. You can build the component from source.
              Installation instructions are not available. Examples and code snippets are available.

            Top functions reviewed by kandi - BETA

            kandi has reviewed xorshift and discovered the below as its top functions. This is intended to give you an instant insight into xorshift implemented functionality, and help decide if they suit your requirements.
            • Returns the next number bits
            • Gets bit mask
            • Ensures that the bits in the remaining bits are available
            • Reads a 64 - bit long
            • Compute the next 32 bits
            • Resets the seed to the given seed
            • Expand the seed array with the given length
            • Resets this generator to a new value
            • Sets the seed value
            • Resets the generator
            Get all kandi verified functions for this library.

            xorshift Key Features

            No Key Features are available at this moment for xorshift.

            xorshift Examples and Code Snippets

            No Code Snippets are available at this moment for xorshift.

            Community Discussions

            QUESTION

            why xorshift random number generator uses the same "amount" of SBR/SBL in all examples?
            Asked 2022-Mar-18 at 06:23

            I was going through a book that explained the xorshift algorithm (I know, basic stuff). Then, while searching a little bit more on the Internet, I found that all the basic examples seem to shift the bits right/left the same "amount" (13, 17, 5).

            For instance:

            ...

            ANSWER

            Answered 2022-Mar-18 at 06:04

            This is actually a lot more subtle and interesting than you might suspect!

            The xorshift random number generator has an interesting theoretical backstory. The use of shifts and XORs corresponds to performing a matrix-vector product where both the matrix and the vector are made of 0s and 1s. The specific matrices in question are derived based on the choices of shift sizes and the directions of those shifts.

            In order for the RNG to perform well (specifically, to not repeat any outputs until all possible values have been generated), the matrix derived by the shifts must be invertible. Most choices of shifts will not give an invertible matrix, and the author of xorshift ran a computer search to find all possible shift sizes that work. In the paper detailing the xorshift family of RNGs, the author detailed the specific choice of shifts you mentioned and says the following:

            It uses one of my favorite choices, [a, b, c] = [13, 17, 5], and will pass almost all tests of randomness, except the binary rank test in Diehard [2]. (A long period xorshift RNG necessarily uses a nonsingular matrix transformation, so every successive n vectors must be linearly independent, while truly random binary vectors will be linearly independent only some 30% of the time.) Although I have only tested a few of them, any one of the 648 choices above is likely to provide a very fast, simple, high quality RNG.

            So in a sense, these numbers satisfy the theoretical necessary conditions needed for the math to work out to make this a good RNG, and the author tested it and singled them out in the original paper, which is why I’m guessing they’re so widely used. But perhaps there’s an even better choice using other numbers from the paper that folks just haven’t gotten around to using yet?

            Source https://stackoverflow.com/questions/71522815

            QUESTION

            Has anyone encounter this this stripping artifact during "RayTracing in one Weekend"?
            Asked 2021-Dec-14 at 22:29

            I am trying to port the "RayTracing in One Weekend" into metal compute shader. I encounter this strip artifacts in my project:

            Is it because my random generator does not work well?

            Does anyone have a clue?

            ...

            ANSWER

            Answered 2021-Aug-30 at 02:43

            I found this link.It says that the primary ray hit point is either above or below the sphere's surface a litter bit due to the float precision error. It is a z-fighting problem

            Source https://stackoverflow.com/questions/68888277

            QUESTION

            How to do unsigned 32 bit arithmetic in Perl?
            Asked 2021-Jul-14 at 18:35

            I would like to implement the following C program in Perl:

            ...

            ANSWER

            Answered 2021-Jul-14 at 18:30

            If you want to simulate the result of 32-bit ops, you can simply apply a mask:

            Source https://stackoverflow.com/questions/68382949

            QUESTION

            xorshift and its variations give unrandom results in C
            Asked 2021-Jun-14 at 09:54

            I'm trying to create a pseudo-random generator API, but numbers generated by xorshift have unrandom nature. You can see the algorithm and tests here:

            ...

            ANSWER

            Answered 2021-Jun-14 at 09:54

            You're looking at random numbers uniformly distributed between 0 and 18,446,744,073,709,551,615 (UINT64_MAX). All numbers between 10,000,000,000,000,000,000 and 18,446,744,073,709,551,615 start with a 1, so the skewed distribution is to be expected.

            Source https://stackoverflow.com/questions/67967747

            QUESTION

            How to pass the output of a function to itself a number of times in RNG?
            Asked 2021-Mar-29 at 22:48

            I'm trying to pass the output of a function in C to itself a number of times but I'm still getting the same answer each time (I tried to pass it by value and by reference I do not know which is the correct one). I have two functions in my program one that does the calculations and it is called xorshift() and the second function has a for loop; to call the function multiple times and it is called foo(). What I want to do exactly is :

            I want to pass (f) to the xorshift function and do the xor and shift operations and then return the output, and this output should go to xorshift function and do the xor and shift operations again and get the output and send it again to xorshift function ..etc I want to do this operation for a number of times.

            Any thoughts or suggestions on how to do it?

            ...

            ANSWER

            Answered 2021-Mar-29 at 22:48

            You just need your inner loop to be:

            Source https://stackoverflow.com/questions/66860118

            QUESTION

            IEEE 754 conformant sqrtf() implementation taking into account hardware restrictions and usage limitations
            Asked 2021-Mar-24 at 23:52

            Follow-up question for IEEE 754 conformant sqrt() implementation for double type.

            Context: Need to implement IEEE 754 conformant sqrtf() taking into account the following HW restrictions and usage limitations:

            1. Provides a special instruction qseed.f to get an approximation of the reciprocal of the square root (the accuracy of the result is no less than 6.75 bits, and therefore always within ±1% of the accurate result).

            2. Single precision FP:

              a. Support by HW (SP FPU): has support;

              b. Support by SW (library): has support;

              c. Support of subnormal numbers: no support (FLT_HAS_SUBNORM is 0).

            3. Double precision FP:

              a. Support by HW (DP FPU): no support;

              b. Support by SW (library): has support;

              c. Support of subnormal numbers: no support (DBL_HAS_SUBNORM is 0).

            I've found one presentation by John Harrison and ended up with this implementation (note that here qseed.f is replaced by rsqrtf()):

            ...

            ANSWER

            Answered 2021-Mar-24 at 23:52

            Computing a single-precision square root via double-precision code is going to be inefficient, especially if the hardware provides no native double-precision operations.

            The following assumes hardware that conforms to IEEE-754 (2008), except that subnormals are not supported and flushed to zero. Fused-multiply add (FMA) is supported. It further assumes an ISO-C99 compiler that maps float to IEEE-754 binary32, and that maps the hardware's single-precision FMA instruction to the standard math function fmaf().

            From a hardware starting approximation for the reciprocal square root with a maximum relative error of 2-6.75 one can get to a reciprocal square root accurate to 1 single-precision ulp with two Newton-Raphson iterations. Multiplying this with the original argument provides an accurate estimate of the square root. The square of this approximation is subtracted from the orginal argument to compute the approximation error for the square root. This error is then used to apply a correction to the square root approximation, resulting in a correctly-rounded square root.

            However, this straightforward algorithm breaks down for arguments that are very small due to underflow or overflow in intermediate computation, in particular when the underlying arithmetic operates in flash-to-zero mode that flushes subnormals to zero. For such arguments we can construct a slowpath code that scales the input towards unity, and scales back the result accordingly once the square root has been computed. Code for handling special operands such as zeros, infinities, NaNs, and negative arguments other than zero is also added to this slowpath code.

            The NaN generated by the slowpath code for invalid operations should be adjusted to match the system's existing operations. For example, for x86-based systems this would be a special QNaN called INDEFINITE, with a bit pattern of 0xffc00000, while for a GPU running CUDA it would be the canonical single-precision NaN with a bit pattern of 0x7fffffff.

            For performance reasons it may be useful to inline the fastpath code while making the slowpath code a called outlined subroutine. Single-precision math functions with a single argument should always be tested exhaustively against a "golden" reference implementation, which takes just minutes on modern hardware.

            Source https://stackoverflow.com/questions/66752842

            QUESTION

            Thread safe high performance random generator
            Asked 2020-Nov-22 at 22:11

            I need a high performance random number generator that is thread-safe. I need only random bytes in the value type (which is ulong for now), not within ranges. I've used the C# built-in Random class, but it was kind of slow and not thread-safe.

            Later I moved to XORShift functions that actually works very fine, but to achieve thread-safeness I need to put the calculation in lock, and that degrades the performance drastically.

            What I'm using to generate a random ulong is the following:

            ...

            ANSWER

            Answered 2020-Nov-20 at 23:29

            Simply create one instance of Rand on each thread. Thread-safe, no locking, thus very performant. This can be achieved using the ThreadStaticAttribute.

            Source https://stackoverflow.com/questions/64937914

            QUESTION

            Java Concurrency in practice “Listing 12.5. Producer-consumer test program for BoundedBuffer.” cyclic barrier await understanding?
            Asked 2020-Sep-28 at 00:54

            I am reading Java Concurrency in Practice and encounter the following code snippet. Listing 12.5 https://jcip.net/listings/PutTakeTest.java

            ...

            ANSWER

            Answered 2020-Sep-28 at 00:54

            The main thread starts npairs producers and npairs consumers before calling await on a barrier. Each if producers and consumers calls await so together with a main thread it allows all threads to go through barrier.

            Source https://stackoverflow.com/questions/64080960

            QUESTION

            C Replacements for srand() and rand()
            Asked 2020-Aug-24 at 07:20

            I'm trying to make a game in C fit under a 3KB limit, and to do so I want to remove all standard library references. The only header I want to have in my program is windows.h and so far I'm doing pretty good.

            The only external references I have are one call each of rand(), srand(), time(), and getch(). This may seem like a lot for a game under 3KB, but the time, rand, and srand functions are only so that when the game starts it can have a random seed.

            rand to get the numbers, srand to set the seed, and time to get random seeds. So if I could find a way to get rid of the excessive random generation procedure, I could get rid of 3/4 std library functions. I'm not so sure what to do about getch though, but ill focus on that later.

            Some people have reccomended xorshifts, but it seems like that requires the type uint32_t, which belongs to stdint.h. I also tried using integers instead, and while the resulting number was random, it was random in the sense that the number given back was random, yet you could depend on it giving you that random number each time. I could give it time as a sort of seed, but then id still have to use the time function. Is there something I'm overlooking, or should I use a different method?

            EDIT: as per request, my compilation flags are -ffunction-sections, -fdata-sections, -s and -Os. my only linker flags are -Wl,--gc-sections and I am not sure what dynamically linked and statically linked libraries are completely, but I have a decent idea. My code as is comes out to 12KB, and if i use UPX i can get it down to 7KB. my code is here:

            ...

            ANSWER

            Answered 2020-Aug-23 at 19:06

            It depends a lot on your requirement on the random generator. If you just want it so that the game will be a bit different every time you play it and not be perfectly deterministic, then just about any random generator will do. Just look online and you'll find examples of primitive random generators.

            Among the simplest (but still reasonably good) is this:

            Source https://stackoverflow.com/questions/63550874

            QUESTION

            Java Concurrency in practice "Listing 12.5. Producer-consumer test program for BoundedBuffer.", per-thread checksum?
            Asked 2020-Jan-10 at 03:40

            I am reading Java Concurrency in Practice and encounter the following code snippet.

            ...

            ANSWER

            Answered 2020-Jan-10 at 03:40

            The per-thread checksum is int sum. Each of these is combined into putSum or takeSum at the end.

            Source https://stackoverflow.com/questions/59674970

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install xorshift

            You can download it from GitHub, Maven.
            You can use xorshift like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the xorshift component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            Install
            Maven
            Gradle
            CLONE
          • HTTPS

            https://github.com/grunka/xorshift.git

          • CLI

            gh repo clone grunka/xorshift

          • sshUrl

            git@github.com:grunka/xorshift.git

          • Download

            Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link

            Consider Popular Java Libraries

            CS-Notes

            by CyC2018

            JavaGuide

            by Snailclimb

            LeetCodeAnimation

            by MisterBooo

            spring-boot

            by spring-projects

            Try Top Libraries by grunka

            fortuna

            by grunkaJava

            Static.js

            by grunkaJavaScript

            konami.js

            by grunkaJavaScript

            jsonrpc

            by grunkaJava