Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3612450
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:00:01+00:00 2026-05-18T22:00:01+00:00

Following is a basic implementation of the Xorshift RNG (copied from the Wikipedia): uint32_t

  • 0

Following is a basic implementation of the Xorshift RNG (copied from the Wikipedia):

uint32_t xor128(void) {
  static uint32_t x = 123456789;
  static uint32_t y = 362436069;
  static uint32_t z = 521288629;
  static uint32_t w = 88675123;
  uint32_t t;

  t = x ^ (x << 11);
  x = y; y = z; z = w;
  return w = w ^ (w >> 19) ^ (t ^ (t >> 8));
}

I understand that w is the returned value and x, y and z are the state (“memory”) variables. However, I can’t understand the purpose of more than one memory variable. Can anyone explain me this point?

Also, I tried to copy the above code to Python:

class R2:
    def __init__(self):
        self.x = x = 123456789
        self.y = 362436069
        self.z = 521288629
        self.w = 88675123
    def __call__(self):
        t = self.x ^ (self.x<<11)
        self.x = self.y
        self.y = self.z
        self.z = self.w
        w = self.w
        self.w = w ^ (w >> 19) ^(t ^ (t >> 8))
        return self.w

Then, I have generated 100 numbers and plotted their log10 values:

r2 = R2()
x2 = [math.log10(r2()) for _ in range(100)]
plot(x2, '.g')

Here is the output of the plot:

plot

And this what happens when 10000 (and not 100) numbers are generated:
plot

The overall tendency is very clear. And don’t forget that the Y axis is log10 of the actual value.

Pretty strange behavior, don’t you think?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T22:00:02+00:00Added an answer on May 18, 2026 at 10:00 pm

    The problem here is of course that you’re using Python to do this.

    Python has a notion of big integers, so even though you are copying an implementation that deals with 32-bit numbers, Python just says “I’ll just go ahead and keep everything for you”.

    If you try this instead:

    x2 = [r2() for _ in range(100)]
    print(x2);
    

    You’ll notice that it produces ever-longer numbers, for instance here’s the first number:

    252977563114
    

    and here’s the last:

    8735276851455609928450146337670748382228073854835405969246191481699954934702447147582960645
    

    Here’s code that has been fixed to handle this:

    ...
    def __call__(self):
        t = self.x ^ (self.x<<11) & 0xffffffff                   # <-- keep 32 bits
        self.x = self.y
        self.y = self.z
        self.z = self.w
        w = self.w
        self.w = (w ^ (w >> 19) ^(t ^ (t >> 8))) & 0xffffffff    # <-- keep 32 bits
        return self.w
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following very basic WCF service implementation: public enum TransactionStatus { Success =
I jave the following mapped superclass that provides a basic implementation for a parent/child
Say I have the following basic if-statement: if (A ~= 0) % do something
If I have the following basic C++ program: #include <iostream> using namespace std; class
I have come across the following basic Tree conflict: Local add, incoming add upon
I'm really struggling to create a valid multidimensional JavaScript array with the following basic
I'm following a basic tutorial for the android jni development at http://permadi.com/blog/2011/12/running-android-ndk-examples-using-eclipse-and-sequoyah/ . Before
I am using Sencha Architect with Extjs 4 and by following the basic example
I've got the following tables: User Basic Data (unique) [userid] [name] [etc] User Collection
The following program is a basic linked list divided in 3 classes. In the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.