Sharing SEEDED random number generator script for roguelikes

Tell us about the 001 game you're working on. Show us screenshots. Discuss, promote and share games with others.
Forum rules
If you would like to post about your game, make sure to include screenshots and a long, well-written, thorough description.

Please be positive and understand that not everyone is skilled at using Map001. Games that are similar to other games, or fan games using commercial games' art are perfectly acceptable.

This forum section is dedicated to the discussion of games made with Map001 only.

You must upload your games to above games section of site. Outside links for games are forbidden in this section.
Yttermayn
001 Supporter
 
Joined: Sat Oct 15, 2011 12:12 am

Sharing SEEDED random number generator script for roguelikes

Postby Yttermayn » Thu Aug 30, 2012 9:49 am

I had a heck of a time coming up with a pseudo random number generator to use in the roguelike (That is initialized by a seed!) I recently started writing. In order to save others who also may need or want a random number generator some time, I am posting my first working script here. Syntax is Srand(A,B) Where A is the minimum value and B is the maximum value of the random number to be returned.
Example: If I wanted a random number between 5 and 50 put into the variable 'somenum', I'd do this: In the 'variable operation' event, choose the variable 'somenum' to store the random number in, leave the operation on 'set' and choose the Srand custom event from the drop down menu (or just type it in "Custom.Srand(5,50)"). If you chose it in the drop down, you'll still need to put in the minimum and maximum parameters. Whichever way you go, it will look like "Custom.Srand(5,50)"
When the script you have inserted this into is run, 'somenum' will be set to a random number.

I will likely clean up this script and improve it as I learn more about 001's scripting quirks. I wrote this assuming the reader can create a custom event and insert a script into it.
Edit: One more note: The algorithm fizzles out if you feed it zero as the seed, and be sure to make Seed global. Also, there is no error checking for this or for if your value for Min is larger than your value for Max. I may add this later.

Script:

Site that helped me develop this PRNG for 001:(Removed link due to games section rules.) EDIT: G.D. It's not even a gaming site. Confuzzled had a very helpful article on LCG based PRNG's that I used to adapt the algorithm to 001 Engine.
Last edited by Yttermayn on Sun Sep 09, 2012 3:27 pm, edited 2 times in total.

User avatar
Indiana 266
001 Forum Master
 
Joined: Fri Feb 26, 2010 5:33 pm
Location: Ontario, Canada

Re: Sharing a random number generator script for roguelikes

Postby Indiana 266 » Thu Aug 30, 2012 11:20 am

Or you could use :usevalue: math- random whole number.
Image
Image
Image
Image
Image
Image

Yttermayn
001 Supporter
 
Joined: Sat Oct 15, 2011 12:12 am

Re: Sharing a random number generator script for roguelikes

Postby Yttermayn » Thu Aug 30, 2012 4:01 pm

Except that you don't get to choose or update the seed. If you want to consistently generate the same dungeon, you'll need that ability. Thanks for trying to poo on it, though. Much obliged.

User avatar
Gamerdude
001 Support
 
Joined: Wed Dec 12, 2007 8:56 pm
Location: Australia

Re: Sharing a random number generator script for roguelikes

Postby Gamerdude » Thu Aug 30, 2012 5:52 pm

I would have said the same thing, as you didn't explain the difference between your script and the built in random number function.

I doubt he was trying to "poo" on it, just trying to point out there was an easier way to generate random numbers.

Anyway, your script looks very handy. Nice work :)
Image
Image

User avatar
macrostrata
001 Admirer
 
Joined: Sat Aug 04, 2012 9:21 pm
Location: Manila

Re: Sharing a random number generator script for roguelikes

Postby macrostrata » Thu Aug 30, 2012 6:57 pm

Huh nice I didn't know we don't have a default function for seeds.

Yttermayn
001 Supporter
 
Joined: Sat Oct 15, 2011 12:12 am

Re: Sharing a random number generator script for roguelikes

Postby Yttermayn » Thu Aug 30, 2012 7:27 pm

Gamerdude: Thanks, and, you may be right. I saw his avatar and made an assumption. :roll:
Macrostrata: Yeah, I did a lot of googling and searching, wasn't much about random dungeon generation in 001, nor anything about generating with a seed like you could with the srand() and rand() functions in C.


Return to Games In Progress

Who is online

Users browsing this forum: No registered users

cron