![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Oct 2008
Posts: 2
Rep Power: 0
![]() |
Hi there, I am new there, and I searched before about my question, unfortunately I am unable to understand them and I post again. Sorry if repeating the same question.
My question is like this, ask the user to key in Max and Min as the random number range, and the random number should be in the range. All work fine but I am unable to prevent some percentage that the random generator will generate the same number. (I set the range between Max and Min must be at least same or greater than 10). Max = top. Min = low. top - low >= 10. The random generator will then generate 6 numbers in an array. c++ Syntax (Toggle Plain Text)
Can anyone tell me how to prevent same number repetition? Thank a lot. ![]() ![]() Last edited by big_k105; Oct 16th, 2008 at 12:21 PM. Reason: Changed quote tag to code tag |
|
|
|
|
|
#2 |
|
Banned
![]() ![]() |
Re: Repeated Random Number
This thread has appeared many times in this forum. One example is linked to at the bottom of this page under "similar threads". http://www.programmingforums.org/thread12570.html
Here is another example that was just posted last week: http://www.programmingforums.org/showthread.php?t=16612 You said you searched but "don't understand them"? What don't you understand about the code? Or is your question something slightly different?
__________________
Looking for tough programming challenges? Try participating in Sane's Monthly Algorithms Challenges! Composing Techno is a little side hobby of mine. Techno by DJ Sane. All free for download. |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Oct 2008
Posts: 2
Rep Power: 0
![]() |
Re: Repeated Random Number
http://www.programmingforums.org/showthread.php?t=16612
The thread was afterward goes into Java thing isn't? I am just newbie to C++ and currently only been tough until array... http://www.programmingforums.org/thread12570.html for(i=0;i<100;++i) a[i] = i+1; for(i=0;i<100;++i) swap(a[i], a[rand()%100]); Sorry I can't link it to my question, can you please give an short explanation? Thank for your kind help. ![]() ![]() |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Sep 2008
Posts: 3
Rep Power: 0
![]() |
Re: Repeated Random Number
Well, if you read the whole threads, but not just checking the question, you would have found the "link" to your question - srand() function
![]() |
|
|
|
|
|
#5 |
|
<html>#include C++<?php?>
|
Re: Repeated Random Number
If you want to have fun with random numbers then try to look at this code. It was one of the first i have made.
c++ Syntax (Toggle Plain Text)
You maybe need to change "long int sample = 1000000000;" to somethign like "long int sample = 1000000;" or a less number else will this little program make a 5GB txt file ![]() |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| non-repetitive random number | malms | C | 4 | Feb 14th, 2007 1:17 PM |
| Random Number | coldDeath | Python | 1 | Sep 11th, 2005 9:17 AM |
| Random Number & Average Problem | Hadrurus | Java | 6 | Aug 15th, 2005 2:08 PM |
| generate a random number | cwl157 | Java | 3 | Apr 15th, 2005 7:18 PM |
| non repeating random number generation | gencor45 | C# | 2 | Feb 9th, 2005 1:11 AM |