made rand static to be used in the mainloop. changed the name to avoid clashes