Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Random number generation

How do I generate random numbers in a column of cells but avoid duplications.
i.e. Every cell contains a unique whole number from a specific range.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default Random number generation

have a look he
http://www.ozgrid.com/VBA/RandomNumbers.htm

Neil Higgins wrote:
How do I generate random numbers in a column of cells but avoid duplications.
i.e. Every cell contains a unique whole number from a specific range.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 146
Default Random number generation

Hello I just made this as I was also intruiged on how to do this, not the
best way to do it no doubt but uses a bucket search and displays them in
order.

Sub randomCol()
Dim bucket() As Boolean
Dim whichCol As String
Dim rndArray() As Integer
Dim howManyRows As Integer
Dim j As Integer
Dim i As Integer

rollSize = 100 'Go up to
howManyRows = 10 'How many different numbers you want along with how
many rows to go down
ReDim bucket(1 To rollSize)

For i = 1 To howManyRows
If bucket(reroll(rollSize)) = False Then
bucket(reroll(rollSize)) = True
Else
i = i - 1
End If
Next i

j = 1
For i = 1 To UBound(bucket)
If bucket(i) = True Then
Sheets("Sheet1").Cells(j, 1).Value = i
j = j + 1
End If
Next i
End Sub

Private Function reroll(rollSize) As Integer
Randomize
reroll = Int((Rnd * rollSize) + 1)
End Function


One of the problems is you can end up with a huge ass array if you wish lots
of random numbers.

Hope this helps! :)

"Neil Higgins" wrote:

How do I generate random numbers in a column of cells but avoid duplications.
i.e. Every cell contains a unique whole number from a specific range.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default Random number generation


Or maybe the free Special Randoms workbook will do what you want.
Download from the Products page at... http://www.realezsites.com/bus/primitivesoftware
Numbers generated in a new workbook - then copy | paste where you want.
--
Jim Cone
Portland, Oregon USA

(Excel Add-ins / Excel Programming)


"Neil Higgins"
<Neil
wrote in message
How do I generate random numbers in a column of cells but avoid duplications.
i.e. Every cell contains a unique whole number from a specific range.
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 115
Default Random number generation

"Neil Higgins" wrote:

How do I generate random numbers in a column of cells but avoid duplications.
i.e. Every cell contains a unique whole number from a specific range.


Chip Pearson has a good one he
http://www.cpearson.com/Excel/randomNumbers.aspx

The "no duplicates" version is about midway down the page...
Reply
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
random number generation Ahmad Excel Discussion (Misc queries) 3 November 6th 06 06:27 PM
Random Number Generation MB06 Excel Programming 5 February 10th 06 08:42 PM
random number generation scotjo Excel Worksheet Functions 4 January 9th 06 04:06 PM
random number generation DSpec Excel Worksheet Functions 7 October 3rd 05 01:41 PM
random number generation nyn04[_5_] Excel Programming 3 September 22nd 04 02:13 PM


All times are GMT +1. The time now is 04:12 AM.

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"