People like to see stuff done in different waysavansc wrote:thats what you call spin. you should be in politics.
if everyone programmed the same that would
be very bad and I hate politics. I will stick with
programming

Moderator: Coders of Rage
People like to see stuff done in different waysavansc wrote:thats what you call spin. you should be in politics.
I would be willing to bet that this doesn't use rand().dandymcgee wrote:Top Secret level encryption,
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
Something more sophisticated in my opinion.MarauderIIC wrote:I would be willing to bet that this doesn't use rand().dandymcgee wrote:Top Secret level encryption,
like?zodiac976 wrote:Something more sophisticated in my opinion.MarauderIIC wrote:I would be willing to bet that this doesn't use rand().dandymcgee wrote:Top Secret level encryption,
Don't ask me I am not that smartavansc wrote:like?zodiac976 wrote:Something more sophisticated in my opinion.MarauderIIC wrote:I would be willing to bet that this doesn't use rand().dandymcgee wrote:Top Secret level encryption,
Like some calculation of Pi.avansc wrote:like?
No. If you don't reseed by calling srand(), they seem to repeat after a few calls to rand(). If you do reseed, and you use time(NULL) to seed with every time, you'll notice more repetition than seeding with the previously generated random number, but it will eventually repeat, either way.RandomDever wrote:Is there a way to have a random range function that never repeats any digit? :|
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
Well said and I didn't know about reseeding againMarauderIIC wrote:Like some calculation of Pi.avansc wrote:like?
Oh, and to sum it up for the OP:No. If you don't reseed by calling srand(), they seem to repeat after a few calls to rand(). If you do reseed, and you use time(NULL) to seed with every time, you'll notice more repetition than seeding with the previously generated random number, but it will eventually repeat, either way.RandomDever wrote:Is there a way to have a random range function that never repeats any digit?
Look at it this way, unsigned ints have a range of 0-4,294,967,295
If you call rand() 4,294,967,297 times, you will have at least one number repeat. But since I doubt that you want 4,294,967,296 unique random numbers -- rather, you probably only want like, 10 -- then after 10 calls, you are guaranteed to repeat. (This is the common-sense Pigeonhole principle, which you can do all sorts of fun things with. For example, if the maximum hairs on a head is 1 million and there are 1 .5 million people in London, then at least 2 people in London have the exact same number of hairs on their head).
In a perfect world, as you approach the 5th number, you'll have a 50% chance of your 6th number being a repeat. As you approach the 9th number, you have a 90% chance of your 10th number being a repeat. But since computers are psuedo-random, as opposed to truly random, your chances of getting a duplicate result always seem to be higher. You can reduce the chance of getting a duplicate by seeding with time(NULL) on the first call and reseeding with the last result of rand() [pure, not modded down to your range] on each subsequent call to rand().
Hopefully that totally answers the question.
Thanks and http://elysianshadows.com/phpBB3/viewto ... 303#p42303zodiac976 wrote:Well said and I didn't know about reseeding again ;).
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
Sorry, I will avoid it next time.MarauderIIC wrote:Thanks and http://elysianshadows.com/phpBB3/viewto ... 303#p42303zodiac976 wrote:Well said and I didn't know about reseeding again.
Which is why avansc asked if you read, I think, since your answer was nearly spot-on to what I had already written.
Depending on the organization.. I'll take that bet.MarauderIIC wrote:I would be willing to bet that this doesn't use rand().dandymcgee wrote:Top Secret level encryption,
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
Code: Select all
srand((unsigned)time(NULL));
srand(rand()%3000);
srand(rand()%3000);
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
It's just a waste of CPU time.Ginto8 wrote:another (you could say more random) way of seeding it is something like this:if you do that before each random number, it would be a (little bit of a) waste of CPU power, but it would probably make it seem a little more random.Code: Select all
srand((unsigned)time(NULL)); srand(rand()%3000); srand(rand()%3000);