Author Topic: Suggestion: Random (min int, max int) (SOLVED)  (Read 1323 times)

Moox

  • Losttraveler
Suggestion: Random (min int, max int) (SOLVED)
« on: 14 Jun 2004, 23:01 »
Well I am taking time off from my game to port one of my old basic games into ags . One key feature is a random dungeon generator. I want to have a random forest dungeon, mine dungeon, etc...
To accomplish this their needs to be both a minimum and a maximum so I can set the range between the backgrounds, perhaps 1-20 are forest 20-40 are cave. I need random number between 20-40 for a cave. One possible work around would be something like If int is between 0-20 then redo random. But a script like that could be kinda slow and time consuming to add to every room. Could you add a min range to random please cj
« Last Edit: 18 Oct 2005, 02:08 by strazer »

dave y

  • Guest
Re: Suggestion: Random (min int, max int);
« Reply #1 on: 14 Jun 2004, 23:14 »
Random(20) + 20

gives you the same effect

Re: Suggestion: Random (min int, max int);
« Reply #2 on: 14 Jun 2004, 23:18 »
You can define your own custom function:

Global script

function RandomEx(int min, int max) { return (min + Random(max-min)); }

Script header (so you can use it outside the global script, ie in rooms)

import function RandomEx(int min, int max);

Moox

  • Losttraveler
Re: Suggestion: Random (min int, max int);
« Reply #3 on: 14 Jun 2004, 23:35 »
I didnt know that was possible, thanks