Created
May 28, 2014 16:17
-
-
Save joonjoonjoon/13872ab7777a553a3fd6 to your computer and use it in GitHub Desktop.
workaround for FlxRandom
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private static var seed:Int; | |
| private static var increment:Int; | |
| public static function GetNextSeededRandom():Float | |
| { | |
| increment++; | |
| FlxRandom.globalSeed = seed; | |
| var result:Float = 0; | |
| for (i in 0...increment) | |
| { | |
| result = FlxRandom.float(); | |
| } | |
| return result; | |
| } | |
| public static function SetSeed(newSeed:Int):Void | |
| { | |
| increment = 0; | |
| seed = newSeed; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @joonjoonjoon. I'm not sure this is necessary, and it could certainly get very inefficient and slow when your increment gets big. I'm wondering if there might be an easier way . . . Have you considered something like this?
Or if you also need the global seed (as in, the currentSeed that applies globally) to persist:
You could move this behavior into a separate
RandomSeedclass or something: