Page 1 of 1

PostPosted: Tue Aug 14, 2001 9:05 pm
by Dman
Um, I didn't really understand the usage of pseed(). Could someone please explain it?

http://openpalm.tripod.com

PostPosted: Wed Aug 15, 2001 12:47 am
by jstadolnik
Enclosed is some code sample showing how pseed() works. In short it allows you to re-create a stream of random numbers.

For example, suppose you create a game which has a "random" layout of walls, creatures, and objects. Each level in the game can have its own seed value. This way each unique level will always appear the same, yet you don't have to save away all the details of each level to regenerate it... just the seed.

Joe

<pre id=code><font face=courier size=2 id=code>
//seed.c
library "PToolboxLib"

print(int seed) {
int i=18;
pseed(seed);
while(i--) puts(prand(10)+",");
puts("\n");
}

main() {
clear();
puts("3 loops with same seed...\n");
print(7);
print(7);
print(7);
puts("loop with new seed...\n");
print(2);
}
</font id=code></pre id=code>