Using of <random> instead of boost random and thread safety fix.

Groups index is used under lock.