|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Re: Replacing duplicates in a randomly generated array
Add the following header:
{$APPTYPE CONSOLE} ... and change "word" to "dword" (4 places), and you've got a 32-bit Delphi console app which will select 100 non-duplicate random values from a pool of one million in less than 0.004 seconds on an 8-year-old desktop PC. |
|
#2
|
||||
|
||||
|
Re: Replacing duplicates in a randomly generated array
Quote:
|
|
#3
|
||||
|
||||
|
Re: Replacing duplicates in a randomly generated array
@Zholl:
The algorithm I posted works very fast for very large sample spaces. It does not require the overhead of removing samples from the array, nor does it require the overhead of shuffling the entire sample space. The header is to allow 16-bit TP7 code to be compiled by Delphi into a 32-bit app that can run natively under Windows. You can code the algorithm in your language of choice. |
|
#4
|
||||
|
||||
|
Re: Replacing duplicates in a randomly generated array
I'll note that I've used Greg McKaskle's last solutions in several simulation and test applications in Java by using something similar to this:
Code:
LinkedList<Object> someList = getList(); Collections.rotate(someList, (int)(Math.random()*(someList.size() - 1))); Object randomObject = someList.remove();
|
|
#5
|
|||
|
|||
|
Re: Replacing duplicates in a randomly generated array
You may use an obscure programming language when it isn't mentioned for the first 6 pages of google results...
|
|
#6
|
||||
|
||||
|
Re: Replacing duplicates in a randomly generated array
I'll just call it pseudo-code from now on :-) I just re-ran it with a larger sample space. On an 8-year-old desktop PC running XP Pro, it took a little over 1 millisecond to select 10 thousand non-dup random samples from a 100 million sample space (neglecting the time required to populate the sample space). |
|
#7
|
||||
|
||||
|
Re: Replacing duplicates in a randomly generated array
A note about random number generation. My understanding.....
Back in the day, over 15 or 20 years ago most 'random' numbers were software algorithms that were not that random. If you knew the algorithm, seeding and such you could predict the next 'random' number. People that really needed random numbers built external circuits that essentially measured the kTb voltage across a resistor. Basically naturally occurring resistor noise. Then about 15 years ago Intel basically embedded this circuit into the Pentium processor. Starting with a particular revision processor, you could read a register in the processor that would give you a random number, that was based on thermal noise, not a mathematical pseudorandom generator. So now I'm curious. Does anyone know how to get to this function from Window or linux ? edit: more on the topic is here http://http://en.wikipedia.org/wiki/...mber_generator Last edited by ebarker : 01-08-2012 at 13:08. |
|
#8
|
||||
|
||||
|
Re: Replacing duplicates in a randomly generated array
...
Last edited by Ether : 01-08-2012 at 14:26. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|