2

I am looking for a random number generator in actionscript 3.0 that i can seed. The Math.random() does not have this functionality.

Thanks.

0

2 Answers 2

3

Here you go http://gskinner.com/blog/archives/2008/01/source_code_see.html

Sign up to request clarification or add additional context in comments.

2 Comments

@antiz Yeah people on here are brutal sometimes. I gave you both a +1 to offset it and then some.
Using a bitmap with perlin noise? I'm sure it works but it sounds quite hackish, isn't it?
3

I mostly use this seeded random function, which is very fast.

var seed:int = 777;

const MAX_RATIO:Number = 1 / int.MAX_VALUE;
const MIN_MAX_RATIO:Number = -MAX_RATIO;

function random():Number
{
   seed ^= (seed << 21);
   seed ^= (seed >>> 35);
   seed ^= (seed << 4);
   if (seed > 0) return seed * MAX_RATIO;
   return seed * MIN_MAX_RATIO;
}

sources:
http://blog.stroep.nl/2012/07/random-seed-actionscript/
http://en.wikipedia.org/wiki/Linear_congruential_generator

7 Comments

the link is dead. Could you explain a bit more about your answer? The other upvoted solution uses a bitmap data with perlin noise. I'm sure there must be something cleaner.
I added a link to my blog, with a simple example how to use this. Basically it shifts around numbers, which gives random seeming values, but in the same order if you use the same seed.
Is this supposed to only return negative numbers? When using this I had to change the second to last line from seed < 0 to seed > 0.
It is supposed to return a Number between 0-1. I updated the code in the answer to if (seed > 0), not sure why I had the < 0 in the first place..
Now that is a helpful comment
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.