Adventure Game Studio

AGS Support => Modules, Plugins & Tools => Topic started by: Akumayo on Sun 23/10/2005 04:29:19

Title: MODULE: Advanced Randoms v1.0
Post by: Akumayo on Sun 23/10/2005 04:29:19
Hey guys, modified the module, renamed it and stuff, and it has a new function now (that I like a lot).  Here's the basics:


RandomBoundries(int min, int max);


This function is a general boundry random, inserting values:

RandomBoundries(7, 10);

Will return 7, 8, 9, or 10.


RandomDice(int amountofnumbers, int firstnumber, int secondnumber, optional int thirdnumber, optional int fourthnumber, optional int fifthnumber, optional int sixthnumber, optional int seventhnumber, optional int eigthnumber);


This function is a more advanced random choser.
Enter first the amount of numbers you want the function to
chose from, (2 minimum), and then enter the values.  Ex:

RandomDice(4, 5, 6, 10, 33);

Will return 5, 6, 10, or 33.


RandomWeightedDice(int firstcheatnumber, int firstnumberchance, int secondcheatnumber, int secondnumberchance, optional int thirdcheatnumber, optional int thirdcheatnumberchance, optional int fourthcheatnumber, optional int fourthcheatnumberchance);


This function is an advanced version of RandomDice.  It allows
for a certain chance of a number being called.  Chance values
must add up to total 100, and should not be negative to avoid
odd actions.  The default chosing requires four numbers, if you
want less, enter 0 for the chance of the number you do not wish
to appear.  Ex:

RandomWeightedDice(3, 30, 7, 60, 11, 10, 0, 0);

Will return 3 30% of the time, 7 60% of the time, and 11 10% of the time.

Created by Akumayo, with the help of strazer, Ashen, and scotch.

Download here (http://www.2dadventure.com/ags/AdvancedRandoms.zip) (Thanks Neole!)
Title: Re: MODULE: Ultimate Randoms v2.0
Post by: SSH on Mon 24/10/2005 08:29:00
Can you add Gaussian, Poisson, Normal distributions, as well as Uniform? ;D

The other solution to the issue of parameters is to pass a "Random format string", so that you can say the probabilities of different outcomes:

x = SuperRandom("50:3 20:5 10:8 10:9 5:101 5:1001");

which would return 3 50% of the time, 5 20% of the time, etc

Title: Re: MODULE: Ultimate Randoms v2.0
Post by: Kweepa on Mon 24/10/2005 16:57:44
There's a good article in the book AI Game Programming Wisdom 2 about random numbers for choices in games. The gist is that random choices can sometimes look decidedly un-random to the player (eg ten coin tosses, ten heads), and the solution is a Filtered Random class that removes seemingly unlikely sequences (eg 12121212, 11111111, 11221122) while keeping the overall percentage chances for decisions. Perhaps you could implement that :=
Title: Re: MODULE: Ultimate Randoms v2.0
Post by: SSH on Mon 24/10/2005 17:14:19
Interestingly, pseudo random number generators almost never generate very unlikely patterns such as 1000 instances of the sdame number in a row. However, a TRUE random number generator can generate such patterns. Hence, tetris games shoudl always be playabel forever in theory, as only the correct, highly unlikely,  pattern of S and Z pieces can make the "perfect" tetris player lose.

Title: Re: MODULE: Ultimate Randoms v2.0
Post by: Kweepa on Mon 24/10/2005 22:42:46
Quote from: SSH on Mon 24/10/2005 17:14:19
Interestingly, pseudo random number generators almost never generate very unlikely patterns such as 1000 instances of the sdame number in a row.

That's true, but the trend these days is to "better" random number generators such as the Mersenne Twister that score very high on "true" randomness. It won't produce 1000 instances of the same number but it might produce 5, which "feels" un-random. Say for example you wanted a guard to perform an idle at the end of a walk path. If he did the same thing 5 times when you've asked for a random choice from 3 idles, it's probably not what you wanted.
And more simple random number generators such as mod prime based generators tend to have patterns in the low order bits (which are often masked off to generate binary decisions).
Title: Re: MODULE: Ultimate Randoms v2.0
Post by: Candle on Sun 20/11/2005 03:41:30
I have three sounds I want to use this to play in game random . but not one right after the other ,maybe 10 to 20 sec apart.
Would this work for that? and how would I do it?
Title: Re: MODULE: Ultimate Randoms v2.0
Post by: monkey0506 on Wed 23/11/2005 07:06:22
Actually having re-read through it, I think you would be better off (for your purposes) using the built-in Random function.

int i = 0;
bool used[3];
while (i < 3) {
  int j = Random(2);
  if (!used[j]) PlaySound(j + 1);
  used[j] = true;
  j = Random(10) + 10;
  Wait(j); /* wait a random amount of time o_0!!! -- between 10 and 20 seconds */
  i++;
  }


That would play all 3 sounds (in a random order) with a random amount of time between 10 and 20 seconds between each.  Just as an example...