Thank you guys for replying and especially Tom S for explaining this, I get it now. It wasn't D it was me. What works great is what Dave suggested return (cast(float)(rand()%101)-50)/50; but this shorter version works also return (rand()%101)-50.)/50; What I have learned is to be more careful with unsigned numbers and - :)