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

How would i set up a macro to generate six random numbers
in consecutive cells between 1 and 50. There cannot be a
any duplicate numbers though?

Thanks in advance for your help.

Ed
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 837
Default Random number

The usual way to avoid duplicates is to use two columns: one column
containing the numbers 1 ... 50 and the second column containing random
numbers. Sort both columns based on the second column, and take the
first six numbers from the first column.

Jerry

ed wrote:

How would i set up a macro to generate six random numbers
in consecutive cells between 1 and 50. There cannot be a
any duplicate numbers though?

Thanks in advance for your help.

Ed


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Random number

Ed,

Here's one way.

Goto ToolsOptions and on the Calculation tab click the Iteration checkbox
(this will suppress circular reference messages)
Put this formula in A1 and copy down to A50
=IF(OR(A1=0,B11),INT(RAND()*100),A1)
Put this formula in B1 and copy down to B50
=COUNTIF(A:A,A1)

Change the RAND function to your max values, but make sure it is large
enough to allow unique numbers (90 was the lowest I could get)

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"ed" wrote in message
...
How would i set up a macro to generate six random numbers
in consecutive cells between 1 and 50. There cannot be a
any duplicate numbers though?

Thanks in advance for your help.

Ed



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Random number

You could also try this fairly simple method:-

In A1 type =RAND()
Copy this to A2:A50

In B1 type =RANK(A1,a$1:a$50)
Copy this to B2:B6

You will be *ranking* each of the random numbers in A1 to A6 as they appear
within the group A1 to A50 and showing this ranking as an integer in B1:B6

In theory this method could yield duplicates but probably not - given the
small quantity of numbers involved i.e. 6 from 50.

HTH
Dave



"ed" wrote in message
...
How would i set up a macro to generate six random numbers
in consecutive cells between 1 and 50. There cannot be a
any duplicate numbers though?

Thanks in advance for your help.

Ed



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Random number

In theory, it won't produce duplicates since the period of the RAND
algorithm is well in excess of 50 and numbers do not repeat within the
period.

--
Regards,
Tom Ogilvy

"Dave B" wrote in message
...
You could also try this fairly simple method:-

In A1 type =RAND()
Copy this to A2:A50

In B1 type =RANK(A1,a$1:a$50)
Copy this to B2:B6

You will be *ranking* each of the random numbers in A1 to A6 as they

appear
within the group A1 to A50 and showing this ranking as an integer in B1:B6

In theory this method could yield duplicates but probably not - given the
small quantity of numbers involved i.e. 6 from 50.

HTH
Dave



"ed" wrote in message
...
How would i set up a macro to generate six random numbers
in consecutive cells between 1 and 50. There cannot be a
any duplicate numbers though?

Thanks in advance for your help.

Ed





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
Addding a Random number to a fixed number..... Dermot Excel Discussion (Misc queries) 6 August 20th 06 12:17 PM
How can I match a random number with closest number from sequence? Matt Excel Worksheet Functions 4 August 3rd 06 01:22 AM
same number appears in a random number generator Carmel Excel Worksheet Functions 4 May 28th 06 12:22 AM
Generating (in a random order)each number once from a given number Neil Goldwasser Excel Worksheet Functions 2 December 2nd 05 11:27 PM
How do I find random number in list of random alpha? (Position is. jlahealth-partners Excel Discussion (Misc queries) 0 February 8th 05 05:31 PM


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

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

About Us

"It's about Microsoft Excel"