Random Float code like BlitzBasic (C# using SDK)
Übersicht

![]() |
mcunha98Betreff: Random Float code like BlitzBasic (C# using SDK) |
![]() Antworten mit Zitat ![]() |
---|---|---|
Hello,
I convert an old system of particles from BlitzBasic to C# using Blitz SDK, but the Random Float I wrote dont work exactly like Blitz. Some idea ? Code: [AUSKLAPPEN] private float RandomFloat(float min, float max) { float resultx = (float)(myRandom.NextDouble() * (max - min)) + min; return resultx; } See the results between the 2 tools, the parameters is the same, but when the RandomFloat is called the result is very different... ![]() |
||
Mauricio Cunha
http://mcunha98.blogspot.com |
![]() |
Noobody |
![]() Antworten mit Zitat ![]() |
---|---|---|
I don't really know C#, but assuming that myRandom.nextDouble() returns a random Double in range 0 to 1, your code would be right.
However, if it just returns any random Double, your code would be: Code: [AUSKLAPPEN] private float RandomFloat(float min, float max)
{ float resultx = (float)(myRandom.NextDouble() % (max - min)) + min; return resultx; } Where % is the modulo - operator. Either way, these forums are only for German-speaking users. Next time, post on the English board (found here) |
||
Man is the best computer we can put aboard a spacecraft ... and the only one that can be mass produced with unskilled labor. -- Wernher von Braun |
![]() |
mcunha98 |
![]() Antworten mit Zitat ![]() |
---|---|---|
Using your suggestion, the values really is very diferent...
Blitz3D > Random value between -10 and 10 : -9.92813 Blitz3D > Random value between -10 and 10 : -4.1011 Blitz3D > Random value between -10 and 10 : 1.97098 Blitz3D > Random value between -10 and 10 : 5.78293 Blitz3D > Random value between -10 and 10 : 7.08145 Blitz3D > Random value between -10 and 10 : 2.51541 Blitz3D > Random value between -10 and 10 : -4.0419 Blitz3D > Random value between -10 and 10 : 9.70047 Blitz3D > Random value between -10 and 10 : 5.06424 Blitz3D > Random value between -10 and 10 : -3.37814 Blitz3D > Random value between -10 and 10 : -2.62436 Blitz3D > Random value between -10 and 10 : 4.48135 Blitz3D > Random value between -10 and 10 : 3.09921 C# > Random value between -10 and 10 : 9,330357 C# > Random value between -10 and 10 : -9,232029 C# > Random value between -10 and 10 : 0,8192587 C# > Random value between -10 and 10 : 8,866722 C# > Random value between -10 and 10 : 6,788763 C# > Random value between -10 and 10 : -9,012728 C# > Random value between -10 and 10 : -6,965828 C# > Random value between -10 and 10 : 2,521488 C# > Random value between -10 and 10 : 2,254827 |
||
Mauricio Cunha
http://mcunha98.blogspot.com |
![]() |
Noobody |
![]() Antworten mit Zitat ![]() |
---|---|---|
I think your function returns different values, because Blitz uses a different algorithm to create random numbers than C# does.
That doesn't really matter - as long the random values remain in your specified interval, everything's fine. In your screenshot it looks much like the random numbers were on a highly different scale than your min/max - values, causing all the particles to fly downwards really fast. Just give it a try using my code, it should work. |
||
Man is the best computer we can put aboard a spacecraft ... and the only one that can be mass produced with unskilled labor. -- Wernher von Braun |
![]() |
ChaosCoder |
![]() Antworten mit Zitat ![]() |
---|---|---|
Why is the gravityvalue in BMax between 0.02 and 0.07 and in C# between 1 and 4? that would cause a 100 times greater acceleration downwards and would lead to exactly this behaviour of the particles...
Or is this exactly the problem, that C# generates these higher double values for the gravity? Then I have no idea ![]() |
||
Projekte: Geolaria | aNemy
Webseite: chaosspace.de |
![]() |
mcunha98 |
![]() Antworten mit Zitat ![]() |
---|---|---|
Noobody
I did. I put your "modulo" in function, the results really improve, but not is the spected effect. ChaosCoder This is it, the problem is how I give random values to the particle system in same standard of Blitz. |
||
Mauricio Cunha
http://mcunha98.blogspot.com |
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group