[feature request] Randomizer
-
- Posts: 69
- Joined: Sun Oct 12, 2003 3:42 pm
- Location: Germany
[feature request] Randomizer
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 ?
There's one already.
Here's an example I am using to place models randomly, like trees, in a 10.000x10.000 units square:
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;
}
Yes this function is ANSI-C thus supposed to be platform-independant.
http://www.cplusplus.com/ref/cstdlib/rand.html
http://www.cplusplus.com/ref/cstdlib/rand.html
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.
-
- Posts: 91
- Joined: Fri Oct 31, 2003 5:03 am
Not to toot my own horn but...
DustyEngine Randgen
hehe Just a wrapper for rand() but works on every platform I've used.
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
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
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