Post by mcunha98 on Mar 27, 2009 19:46:32 GMT
Hi,
I have a great problem to solve.Maybe, someone can help me...
I use Blitz3D SDk with C# to develop my game, and I got some pieces of code for make a system of particles in my game. But the problem is the use of Rnd() function of 'native' Blitz Basic.
When I use the same code after conversation to C#, the results not is the same (actually, not is similar), because the random operator of Blitz work with float values, but C# have only integer and double (0-1), I search on internet for find a good RandomFloat (min, max) function, but is impossible find some function work like Blitz.
The conversation of BlitzCode to C# is revised twice, and is ok, the real problem is the random factor generated.
Some idea ?
I have a great problem to solve.Maybe, someone can help me...
I use Blitz3D SDk with C# to develop my game, and I got some pieces of code for make a system of particles in my game. But the problem is the use of Rnd() function of 'native' Blitz Basic.
When I use the same code after conversation to C#, the results not is the same (actually, not is similar), because the random operator of Blitz work with float values, but C# have only integer and double (0-1), I search on internet for find a good RandomFloat (min, max) function, but is impossible find some function work like Blitz.
private float RandomFloat(float min, float max) {
/*
float rMin = 0.5f * ((float)myRandom.NextDouble());
float rMax = 0.5f * ((float)myRandom.NextDouble());
if (min < 0) rMin = -rMin;
if (max < 0) rMax = -rMax;
float result1 = min + rMin;
float result2 = max + rMax;
float resultx = (float)(result1 / result2);
*/
//outra formula...
//float resultx = (float)(myRandom.Next(0,2) * max * 2 - min % max);
//float resultx = (float)((myRandom.Next(0, 2) * max) * 2 - (min % max));
float resultx = ((float)myRandom.NextDouble() * max) + ((float)myRandom.NextDouble() * min);
//float resultx = (float)(((max - min) + 1) * myRandom.Next(0,2) - min);
//float resultx = (float)myRandom.Next(0, 2) * (max - min) + min;
//float resultx = (float)((max - min) + myRandom.NextDouble()) * (float)(myRandom.NextDouble() / double.MaxValue);
//Debug.Print(DateTime.Now.Ticks.ToString() + " --> O random de " + min.ToString() + " ate " + max.ToString() + " eh " + resultx.ToString());
return resultx;
}
/*
float rMin = 0.5f * ((float)myRandom.NextDouble());
float rMax = 0.5f * ((float)myRandom.NextDouble());
if (min < 0) rMin = -rMin;
if (max < 0) rMax = -rMax;
float result1 = min + rMin;
float result2 = max + rMax;
float resultx = (float)(result1 / result2);
*/
//outra formula...
//float resultx = (float)(myRandom.Next(0,2) * max * 2 - min % max);
//float resultx = (float)((myRandom.Next(0, 2) * max) * 2 - (min % max));
float resultx = ((float)myRandom.NextDouble() * max) + ((float)myRandom.NextDouble() * min);
//float resultx = (float)(((max - min) + 1) * myRandom.Next(0,2) - min);
//float resultx = (float)myRandom.Next(0, 2) * (max - min) + min;
//float resultx = (float)((max - min) + myRandom.NextDouble()) * (float)(myRandom.NextDouble() / double.MaxValue);
//Debug.Print(DateTime.Now.Ticks.ToString() + " --> O random de " + min.ToString() + " ate " + max.ToString() + " eh " + resultx.ToString());
return resultx;
}
The conversation of BlitzCode to C# is revised twice, and is ok, the real problem is the random factor generated.
Some idea ?