Moved srand to call earlier