.Net Random numbers and portability

Working on fractals and procedural generation, I faced an “interesting” problem…

 

.Net Random does not guaranty to produce the same output with the same seed on two different platforms (Framework implementation)… See:
System.Random

 

In most cases I need the result to be the same across platforms (I need to generate the same landscape, event if I change the machine I am working on)… So the only workarounds are to override System.Random or implement my own random number generator.

For a good random number generator example (with tests and proof), see:
Simple Random Number Generator

 

For the design part, I have abstract the System.Random methods with an interface IRandom then developed a “portable” random number generator:

Random design

Random design

 

Some unit testing then go 😉

Advertisements

About Sylvain Bories

Software Developer (.Net, C#) and hobbyist game programmer (Unity 3d, XNA/MonoGame, DirectX). Interested in Green IT, Windows ecosystem, Technology and Science Fantasy.

Posted on February 26, 2013, in Computer science, Programming, Technology and tagged . Bookmark the permalink. Leave a comment.

Comment

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: