   Random numbers
  I am making a random number like this:srand(time(0));int x[6] = { 0 };for(int i = 0; i < 6; i++){    x = rand() % wnd.width(); //wnd.width() is the width of my window}But all of the x values are pretty much the same?Why are they all about the same when it has anywhere from 0-800 to choose from?   
  The standard implementations of rand() have low entropy in the low-order bits. Don't use modulus to clip the results of rand() to your desired range.   ;  How should I limit rand() then? I know of no other way and I'm not sure on how to work one out.Also, Thank you.   ;  One way would be to use rand()/RAND_MAX as a proportion and map that to your range.   ;  One way would be to get a random number, cast it to a float, and divide by whatever the maximum random number is.That will give you a random number between 0 and 1then, multiply that number by the maximum number you want (your screen width) and that will give you an even distrobution of randomness (well, only as good an even distrobution as your random function is!)Of course, the division and float casts make this slower so it's a trade off :PCould you post a screenshot of your output as it is currently?  It may not be a problem of your random numbers not being evenly distributed.   ;  I am getting the same results with:rand()/RAND_MAX*wnd.width();I think I'm getting all 0 all the time.Here's a picture:(They're meant to be clouds but as you see they're all grouped along the x axis)They start off screen a little bit (but they shouldn't as starting position is determined by the random number) so I had to wait for them to come on screen, they move at different speeds which is why some are further ahead.   ;  You need a cast to float.   ;  This is because you failed to cast RAND_MAX or the result of rand() to float. What you are doing is integer division which truncates, so the result is always 0.   ;  Another thing that is hard to tell by your example is exactly WHEN you call srand(time(0));I really hope you do it at the top of main outside of any loops.   ;Quote:Original post by SiCraneYou need a cast to float.Ah, yeah, of course, sorry.Thank you.Quote:Original post by nobodynewsAnother thing that is hard to tell by your example is exactly WHEN you call srand(time(0));I really hope you do it at the top of main outside of any loops.No, it's right at the start of main()   