add stypes.RandXorshift #54
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
stypes.RandXorshift
Constructor Arguments
The input arguments of stypes.RandXorshift is as the following.
0x12345678)None)None)32, and 32 or 64 can be set)The reset input is intentionally omitted to prevent this function from exhibiting deterministic behavior for large unit operations (e.g., iterations of batch learning).
Implementation
The RandXorshift class implements hardware random number generation using the Xorshift algorithm on embedded systems. The Xorshift algorithm is a pseudo-random number generator that utilizes simple bitwise operations to generate a sequence of seemingly random numbers.
To implement the RandXorshift class, I refer to Marsaglia's paper 'Xorshift RNGs' (2003) and update the values according to the data width, as shown in the pseudo-code below. I treat state variables and outputs only as unsigned integers to ensure accurate Xorshift-based pseudo-random number generation implementation, following the paper's method.
Case for 32-bit data width
Case for 64-bit data width
Test
Referring to the test of stypes.Counter, I added
stream_rand_xorshiftand verified whether the pseudo-random number sequence output by stypes.RandXorshift matches the expectation.