Re: TADS random numbers.


17 Aug 1995 12:06:02 GMT

Gerry Kevin Wilson <whizzard@uclink.berkeley.edu> wrote:
> Ok, much better. Now. How do I get rand() to give me truly, or at
> least semi-realistic, real numbers. I need much more unpredictable
> results than I'm getting. Several numbers in a row seem to really
> choke pathetically. If I call randomize() after each, I get a bunch
> of identical numbers. This after having to add self. in front of
> every variable in 200 lines of highly variable intensive code makes me
> want to cry.

It may be the case that you're trying to do something with random
numbers that isn't really appropriate. That is, the TADS random numbers
are perfectly random, but you want them to have certain additional
properties that random numbers do not have.

For example, suppose I have an NPC who wanders around the map randomly,
but it is essential for the player to meet her. If I program the NPC to
really wander around at random (e.g. picking a random direction and
travelling that way), then unless there are lots of bottlenecks in the
map, the likelihood is that in some games the NPC will turn up very
regularly, but in other games she will never appear at all. I would do
better to pick a random number at the start of the game that represents
"number of turns until the NPC turns up" - this ensures that the meeting
eventually takes place but gives the appearance of randomness.

If the problem really is to do with inadequacies in the random number
generator, write one of your own. Look up "linear congruential random
number generator" in an algorithms book.

--
Gareth Rees