Algorithm/randomalg: bugfix

Large N values and N == 0 are now handled properly

Signed-off-by: Artem Plakunov <artacc@lvk.cs.msu.su>