Search code examples
actionscript-3flashprocedural-programmingprocedural-generation

Procedural functions with seed (like road generator)


I've searched around but didn't find a solid answer. I'm building a game in AS3. I have no issue generating random map (2D tiles) for my game, which is basically made of random numbers. How do I obtain the exact same result all the time passing a seed parameter to my function ?

function generate(__xt:uint, __yt:uint){
  var rnd:int;
  for (var i:uint=0; i < __xt; i++){
     for(var j:uint=0; j < __yt; j++){
         rnd = Math.round(Math.random());
         ...
     }   
  }
}

Solution

  • Yes Math.random() doesn't support seeding and if you need it, you have to implement your own PRNG. Take a look in this answer Seedable JavaScript random number generator for the JS, it's quite easy to port one of the answers to as3.