What is the difference between random.normalvariate() and random.gauss() in python?

This is an interesting question. In general, the best way to know the difference between two python implementations is to inspect the code yourself: import inspect, random str_gauss = inspect.getsource(random.gauss) str_nv=inspect.getsource(random.normalvariate) and then you print each of the strings to see how the sources differ. A quick look at the codes show that not only … Read more

How to use to replace rand()?

Is there a reasonably simple way to replace srand() and rand()? Full disclosure: I don’t like rand(). It’s bad, and it’s very easily abused. The C++11 random library fills in a void that has been lacking for a long, long time. The problem with high quality random libraries is that they’re oftentimes hard to use. … Read more

Generate random float between two floats

float RandomFloat(float a, float b) { float random = ((float) rand()) / (float) RAND_MAX; float diff = b – a; float r = random * diff; return a + r; } This works by returning a plus something, where something is between 0 and b-a which makes the end result lie in between a and … Read more