The revolutionary project management tool is here! Plan visually with a single glance and make sure your projects get done.

I need an algorithm to generate Pseudo Random Number Sequences - EXCEPT ... the algorithm must __only use generic arithmetic functionality__ available in most programming languages.

Why? Because I need to write code in C#, Android, C++, Objective-C ... such that, if given the__same beginning seed__ all languages will generate the __exact same pseudo random sequence of results__.

Any one got any idea's?

Why? Because I need to write code in C#, Android, C++, Objective-C ... such that, if given the

Any one got any idea's?

static unsigned long

x=123456789,y=362436069,z=

/* replace defaults with five random seed values in calling program */

unsigned long xorshift(void)

{unsigned long t;

t=(x^(x>>7)); x=y; y=z; z=w; w=v;

v=(v^(v<<6))^(t^(t<<13)); return (y+y+1)*v;}

https://en.wikipedia.org/wiki/Linear_feedback_shift_register

All that is required is generic bit manipulations, such as bit shifting, XOR, AND, negation.... should be no problem in any language you are required to use.

(1) C#:

(2) Android:

(3) C++:

(4) Objective-C:

Fred

I know, I should have taken more math in school, but crafts and drama were soooo much more fun.

Fred

P.S. would sure be nice if I could find a job spewing Shakespeare or making pot-holders.

aaaaaarrrrrgggghhhh!

```
#include <stdint.h>
int main(void)
{
uint32_t lfsr = 1;
unsigned period = 0;
do
{
/* taps: 32 31 29 1; feedback polynomial: x^32 + x^31 + x^29 + x + 1 */
lfsr = (lfsr >> 1) ^ (-(lfsr & 1u) & 0xD0000001u);
++period;
} while(lfsr != 1u);
return 0;
}
```

I hope I am not stating the obvious, but do you realise that only line 10 of the above is all YOU need!? The rest of that code is used for checking the "period" of the LFSR.

Some more sophisticated algorithms may be difficult to implement on platforms that don't provide support for high level languages or large number arithmetic.

If you are looking for simple algorithms and are willing to sacrifice quality of the random sequence generated, we should ask how far you want to go.

Returning a constant 0 every time is a possible, though unlikely result of a truly random sequence, and should be easy to implement on any platform.

Maybe you want to minimally specify the range of numbers to be returned, and to stipulate that each possible value is returned the same number of times over a specified cycle length?

It would also help to know the maximum size of numbers on which it is easy to perform arithmetic on the minimal platform of which you are interested.

All Courses

From novice to tech pro — start learning today.

rand. The sequence is determined by the the initial value ofseed. The code is easily modified to produce numbers within any range, including integers within a range. This code assumes 16 digit integer representation.Open in new window

Or the following if using typeint.Open in new window