reimplementation of rand and srand from stdlib.h