random.seed(): What does it do?

I am a bit confused on what random.seed() does in Python. For example, why does the below trials do what they do (consistently)? >>> import random >>> random.seed(9001) >>> random.randint(1, 10) 1 >>> random.randint(1, 10) 3 >>> random.randint(1, 10) 6 >>> random.randint(1, 10) 6 >>> random.randint(1, 10) 7 I couldn’t find good documentation on this. … Read more

Picking a random element from a set

How do I pick a random element from a set? I’m particularly interested in picking a random element from a HashSet or a LinkedHashSet, in Java. Solutions for other languages are also welcome. 34 Answers 34 int size = myHashSet.size(); int item = new Random().nextInt(size); // In real life, the Random object should be rather … Read more

Is java.util.Random really that random? How can I generate 52! (factorial) possible sequences?

I’ve been using Random (java.util.Random) to shuffle a deck of 52 cards. There are 52! (8.0658175e+67) possibilities. Yet, I’ve found out that the seed for java.util.Random is a long, which is much smaller at 2^64 (1.8446744e+19). From here, I’m suspicious whether java.util.Random is really that random; is it actually capable of generating all 52! possibilities? … Read more

Random / noise functions for GLSL

As the GPU driver vendors don’t usually bother to implement noiseX in GLSL, I’m looking for a “graphics randomization swiss army knife” utility function set, preferably optimised to use within GPU shaders. I prefer GLSL, but code any language will do for me, I’m ok with translating it on my own to GLSL. Specifically, I’d … Read more