I didnt notice this about random :(

This is a discussion on I didnt notice this about random :( within the C++ Programming forums, part of the General Programming Boards category; With the rand() function rand keeps going higher with the number ex: 4 then 15 then 27 then 35 then ...

I didnt notice this about random :(

With the rand() function rand keeps going higher with the number ex: 4 then 15 then 27 then 35 then 41 then 61 then 85 then 99 then 1 < until it reaches the number its max is any way to make that obsolete or is it just the way rand works

even if u first have max as 200 and min as 1 and it comesx out with 56 if u do 100 and min 1 it will be higher

Well, if you use % max, you will get a number from 0 to (max-1). If you add min to that, you will get a number from min to (max-1)+min. If you want to go from min to max, then you need to change what you % by, so that at the end (n-1)+min = max. You should be able to solve that for n.

Writing your own pseudo-random number generator is not all that simple unless you are a big time math guru. There are several open-source algos on the net and there are many books on Amazon for this very thing.

Im aware about the srand thing this is old coding from like 2 months ago was using to test :P.

iMalc wat mistake?

And nvm il just atempt to rite my own random number class

The mistake is what cpjust pointed out. You seem to think this was just someone's coding style advice or something like that, but what you've been told about is the actual cause of the oddity you are seeing in the numbers generated. You fix it by moving the srand to before the loop.
I guess in your defence, many articles about rand don't stress enough that you're not supposed to call srand more than once, unless you want to repeat a previous sequence.

You wont be any better off trying to write your own pseudo random number generator.

The idea would work, but your implementation doesn't. srand() must have access to that initted variable and set it on call, or ... well, you can easily guess what happens when I call srand() with my own seed before ever calling rand().

The idea would work, but your implementation doesn't. srand() must have access to that initted variable and set it on call, or ... well, you can easily guess what happens when I call srand() with my own seed before ever calling rand().