Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / is RND command working good?

Author
Message
Alduce
23
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 18th Jan 2013 11:53
Hello, I am trying to position 1000 little cubes. Each in a random 3D position (using RND command) but I find that these little cubes are positioned with a certain order compared to the other little cubes 3D position.


If I use 100 or 200 little cubes so I find a good random level in their 3D positions but If I start to use 1000 or over little cubes I notice that the little cubes positions are increasingly ordered.
More little cubes more order and less random...

Here my code:


You can see that I trying to randomize from the float variables zone_X#, zone_Y# and zone_Z#.

I know that RND command return an Integer number and maybe this is very wrong cause the pos_X#, pos_Y# and pos_Z# variables are float too.

But the problem remain If I am using this code too:



In this example I am using the RND command using some integer numbers but the problem remains.

So at this point, can I set a random x,y,z position and be sure the randomize job is working good??
Broken_Code
15
Years of Service
User Offline
Joined: 20th Aug 2010
Location: Bremen, Germany
Posted: 18th Jan 2013 14:18 Edited at: 18th Jan 2013 14:20
How large is zone_X#,zone_Y# and zone_Z#?
If it is only 20x15x26 then you'll find the more cubes you use the more ordered it will appear as the cubes are taking up every avaliable space

For example a space from 0,0,0 to 1,1,1 (think vertecies on a cube) then there are 8 possible positions, when these are filled it will look very ordered, even though the rnd() function was used to fill it. I think what you've explained here is the same, only on a larger scale.

Try this function:

I haven't used it recently but it should return a random float between the 2 given values (IB being the lower value and IT being the upper value)
Alduce
23
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 18th Jan 2013 14:41 Edited at: 18th Jan 2013 14:44
HI Broken_Code, your function working really fine! Thank you!
Now I can obtain a real random 3d position of my cubes!

The scary and strange thing is that I got this problem just after I changed my PC.

The code is the same I using with my old PC.. but with my old pc I obtained a good random position just using the code I've posted here..


MAH!? This is not the only thing changed since I am using my new PC..
Broken_Code
15
Years of Service
User Offline
Joined: 20th Aug 2010
Location: Bremen, Germany
Posted: 18th Jan 2013 15:18
Good to hear it worked for you!

I doubt a new PC would have changed anything, maybe you were using a plugin or something?

Anyway, I'm glad to hear you fixed your problem, happy coding!
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 18th Jan 2013 17:30
Here's a general-purpose random float function if you want it:


Shh... you're pretty.
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 18th Jan 2013 17:56
Let us not forget...

number = TIMER()
RANDOMIZE number

You can seed the ramdomize function... If you use the same seed, you will get the same results everytime the application is run, thus giving you control over the randomness somewhat...

Give it something completely random as above, and it should be less obvious...

Hope this helps...

Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 18th Jan 2013 18:51
@V
Yes, I remember being blow away by that little trick. You don't need a variable but I guess you did that because there are people who don't realise they are separate commands.

Shh... you're pretty.
Alduce
23
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 18th Jan 2013 20:41
Thank you guys for additional answers. Interesting
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 18th Jan 2013 22:34
Also do not forget, if you have matrix1 utilities, you have a number of randomization tools. The common one is the Random() function. It will return a floating point random number from 0.0 to 1.0 OR from 0.0 to a specified scale: EG: Percent# = Random(100.0).

Login to post a reply

Server time is: 2026-07-07 00:50:34
Your offset time is: 2026-07-07 00:50:34