Problem in math or Random in flash export?

I have the same exact program running in Unity Desktop (Mac) export and Flash export. My program starts by creating random sets of parameters for 5 cats. The way this happens is a bit complex(its genetic modeling) but the key thing to know is that it uses Random.value and does math in uints that are then stored in bytes in a byte array.

On mac desktop i get a decent random selection, but on Flash they all turn out identical. There are no code differences between the two. Its the same exact unity project in both cases. The effect is shown below.

Help?

Desktop:

alt text

Flash:

alt text

It is possible that the seed of the random generator is not properly initialized on Flash. Try to give a value to it.

// constant value should guarantee identical result in consecutive run.
Random.seed = 42;

Or

// try to get a random seed
yield return new WaitForSeconds( 1.111f );
Random.seed = (int) 100*Time.realtimeSinceStartup;

Another possibility lies with the way you stored your unints. Random.value returns a float between 0 and 1. Because you try to store it as uints in bytes array this may give different result according to Little Endian or Big Endian format.

Apparently the conversion and/or the assignment operators are fairly broken.

I have gotten it to more or less work by using int instead of uint, minimizing the casting, and avoiding all assignment operators.

This is pretty awful though, some major work needs to go into assuring that math in C# gets correctly translated to the flash machine.

I just had this problem and fixed it by rewriting a random function

using UnityEngine;
using System.Collections;

public class RandomGenerator {
  private static int _X = 0;

  public static float value (){
    if(_X == 0) set ();
    _X = (_X * 123456789 + 987654321) % 100000;
    return ((float)_X / 100000f * 0.5f + 0.5f);
  }

  public static float range (int max){ return value() * max; }

  //public static void set (){ _X = System.DateTime.Now.Millisecond * System.DateTime.Now.Second; }
  public static void set (){ _X = Mathf.FloorToInt(Time.realtimeSinceStartup * 10000); }

}

Note that System.DateTime is not available in flash …