How do you use pseed()?

A PocketC native palm library offering native forms and assorted utilities

Postby Dman on Tue Aug 14, 2001 9:05 pm

Um, I didn't really understand the usage of pseed(). Could someone please explain it?

http://openpalm.tripod.com
----[self-mutilation or self-empowerment?]----
Dman
 
Posts: 128
Joined: Mon Jul 02, 2001 8:08 pm
Location: USA

Postby jstadolnik on Wed Aug 15, 2001 12:47 am

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>
jstadolnik
 
Posts: 1741
Joined: Wed Dec 06, 2000 3:34 am
Location: USA


Return to Pocket Toolbox

Who is online

Users browsing this forum: No registered users and 3 guests

cron