Implementation of random algorithms in c