Fastest pseudo-random number-generator: erlang:statistics(io) ?
Tue Nov 24 16:00:09 CET 2009
Today I needed a faster alternative for erlang:now(). It turns out
that using erlang:now() is quite slow: it requires a system call. I
decided to test some alternatives. My requirements are: speed, speed,
speed :) I will use it in a server that is quite busy, so I figured I
could use various system metrics to generate random numbers. I use
these pseudo-random numbers to do load-balancing, log requests at
benchmark results :
This test is spawning 100 concurrent processes, each executing 10000
calls to each function. Two notes:
1. Note that you can only use this function if your server is actually
performing (lots) of IO
2. random:uniform() needs to be seeded for real use (each process
starts the same), I didn't do that.
Based on these tests, erlang:statistics(io) is the clear winner. I
will use it now for picking random elements from lists and replacing
Does anyone have any faster suggestions than erlang:statistics(io) ?
More information about the erlang-questions