[feature request] Randomizer

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
Isometric God
Posts: 69
Joined: Sun Oct 12, 2003 3:42 pm
Location: Germany

[feature request] Randomizer

Post by Isometric God »

As the topic says, I find it very cool to have Randomizer accessible. The change in source code is very little and there are no disadvantages at all. Can this be done ?
Aldo

Post by Aldo »

There's one already.
Here's an example I am using to place models randomly, like trees, in a 10.000x10.000 units square:

Code: Select all

#include <time.h>
int main()
{
 srand((unsigned)time(NULL));
 f32 randomX = rand()%10000;
 f32 randomZ = rand()%10000;
 printf("X = %f\nZ =%f",randomX,randomZ); 
 return 0;
}
hybrid

Post by hybrid »

:lol:
Sure, and now some portable, OS independent wrapper. I guess this is what Isometric God meant. Just like the ITimer which hides os dependent techniques. I guess this is merely API definition, so just make some proposals.
Aldo

Post by Aldo »

The rand() example above is portable, at least it works for me on wondows and linux. Can't say for others :wink:
hybrid

Post by hybrid »

Ok, MSDN says it's also included in the stdlib.h on MS systems, you're right. It just differs in RAND_MAX in several versions, if not all. But that should be a minor problem.
Aldo

Post by Aldo »

Yes this function is ANSI-C thus supposed to be platform-independant.
http://www.cplusplus.com/ref/cstdlib/rand.html
hybrid

Post by hybrid »

But knowing which parts are part of ANSI C and which are just part of POSIX is sometimes quite hard. Furthermore, the difference with wsprintf (need a length parameter or not) had been fixed in ISO C for quite a while, but Microsoft using the old version still for many years. So you often have to work around small API differences.
roninmagus
Posts: 91
Joined: Fri Oct 31, 2003 5:03 am

Post by roninmagus »

Not to toot my own horn but...

DustyEngine Randgen

hehe :) Just a wrapper for rand() but works on every platform I've used.
daveandrews.org - A Christian Programmer's Weblog | Dusty Engine - A Task Engine for Irrlicht
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

jam's sequence generator should give the same results on any system-
http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=11749
much better than rand if you're procedurally making things and you want them to look the same every time
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Post Reply