LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default Best Method

On 3/14/2010 7:14 PM, Dennis Tucker wrote:
What is the best method to make a list of randomized(non-repeating)
numbers between a start value and a end value?



Hi. Just as a side note, the "Best Method" may 'depend' on your size also.
Most algorithms first generate all numbers, then pick unique values.
However, this may be impractical if you have to pick from a size of 1
million. Not quite what I use, but an algorithm may want to branch off
and do something like this if you had to pick 6 numbers from 10,000,000

Sub Demo()
[A1:A6] = WorksheetFunction.Transpose(RandomSample(6, 1, 10000000))
End Sub

Function RandomSample(n, L, H)
Dim d
Dim x

Set d = CreateObject("Scripting.Dictionary")
Do While d.Count < n
x = Int(Rnd * (H - L + 1)) + L
If Not d.exists(x) Then d.Add x, x
Loop
RandomSample = d.keys
End Function


However, your main program would not want to call this routine if you
wanted to pick 100 numbers out of 100. The program would have to loop,
on average, 518 times. Hence, the above would not be efficient.

= = = = = = =
HTH :)
Dana DeLouis



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Method "Method 'Open' of object 'Workbooks' failed [email protected] Excel Programming 2 June 2nd 10 05:28 PM
Please post this thread a correct full method, method about Nast Runsome New Users to Excel 8 February 25th 08 03:29 PM
Please post this thread a complete correct method, method about te Nast Runsome New Users to Excel 0 February 23rd 08 09:42 PM
GetObject method not work after Call Shell Method ben Excel Programming 8 February 21st 06 03:45 PM
Why QUIT method doesn't work after COPY method? surotkin Excel Programming 3 October 26th 05 04:32 PM


All times are GMT +1. The time now is 05:11 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"