#1   Report Post  
jannet
 
Posts: n/a
Default Random Numbers

Lois Patterson, in her book 'Teach Yourself Excel 97' sets an exercise to
create a Lottery Number selector with a set of six random numbers.
=INT(45*RAND)+1 This is fine and easily done.
It goes on to say that by using the IF function it is possible to prevent
the generated numbers being duplicated in the set. After weeks of
frustration I am unable to solve this problem. Please can anyone help?


  #2   Report Post  
Dave O
 
Posts: n/a
Default

Doesn't that contradict the fundamental idea of random numbers? A
truly random number is one that has exactly the same chance of
appearing in a distribution as any other number. By preventing
duplicates you'd be introducing non-randomness.

Will you be applying this information in a lottery ticket exercise,
btw?

  #3   Report Post  
Dave Peterson
 
Posts: n/a
Default

J.E. McGimpsey has a User Defined function that can work for you:

You can find it he
http://www.mcgimpsey.com/excel/udfs/randint.html

If you're new to macros, you may want to read David McRitchie's intro:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

jannet wrote:

Lois Patterson, in her book 'Teach Yourself Excel 97' sets an exercise to
create a Lottery Number selector with a set of six random numbers.
=INT(45*RAND)+1 This is fine and easily done.
It goes on to say that by using the IF function it is possible to prevent
the generated numbers being duplicated in the set. After weeks of
frustration I am unable to solve this problem. Please can anyone help?


--

Dave Peterson
  #4   Report Post  
Bob Phillips
 
Posts: n/a
Default

Here is a formula way

First, ensure dell A1 is empty and goto ToolsOptions and on the Calculation
tab check the Iteration checkbox to stop the Circular Reference message.


Next, type this formula into cell B1

=IF(($A$1="")+(AND(B10,COUNTIF($B$1:$B$6,B1)=1)), B1,INT(RAND()*45)+1)


it should show a 0


Copy B1 down to B6.


Finally, put some value in A1, say an 'x', and all the random numbers will
be generated.


They won't change.


To force a re-calculation, clear cell A1, edit cell B1, don't change it,
just edit to reset to 0, copy B1 down to B6, and re-input A1.



--

HTH

RP
(remove nothere from the email address if mailing direct)


"Dave Peterson" wrote in message
...
J.E. McGimpsey has a User Defined function that can work for you:

You can find it he
http://www.mcgimpsey.com/excel/udfs/randint.html

If you're new to macros, you may want to read David McRitchie's intro:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

jannet wrote:

Lois Patterson, in her book 'Teach Yourself Excel 97' sets an exercise

to
create a Lottery Number selector with a set of six random numbers.
=INT(45*RAND)+1 This is fine and easily done.
It goes on to say that by using the IF function it is possible to

prevent
the generated numbers being duplicated in the set. After weeks of
frustration I am unable to solve this problem. Please can anyone help?


--

Dave Peterson



  #5   Report Post  
Ragdyer
 
Posts: n/a
Default

One way would be to create a list of 45 random numbers with the Rand()
function, say in an out-of-the-way area of your sheet.
Then use a formula which positions (ranks) each cell in this list in
numerical order, and then references the cells ranking against it's actual
row placement, thus eliminating the possibility of any duplication, since a
tied result cannot place 2 cells in the same row position.

This is more properly referred to as a "random order" of set values, instead
of *true* random numbers.

In Z1 enter
=RAND()
And copy down to Z45.

Then, enter this formula anywhe

=INDEX(ROW($A$1:$A$45),RANK(Z1,$Z$1:$Z$45))

And copy down for 6 rows to obtain 6 numbers,
Or copy any number of rows to return that amount of numbers.
--
HTH,

RD

---------------------------------------------------------------------------
Please keep all correspondence within the NewsGroup, so all may benefit !
---------------------------------------------------------------------------
"jannet" wrote in message
...
Lois Patterson, in her book 'Teach Yourself Excel 97' sets an exercise to
create a Lottery Number selector with a set of six random numbers.
=INT(45*RAND)+1 This is fine and easily done.
It goes on to say that by using the IF function it is possible to prevent
the generated numbers being duplicated in the set. After weeks of
frustration I am unable to solve this problem. Please can anyone help?





  #6   Report Post  
 
Posts: n/a
Default

Dave O wrote:
Doesn't that contradict the fundamental idea of random numbers?
A truly random number is one that has exactly the same chance of
appearing in a distribution as any other number. By preventing
duplicates you'd be introducing non-randomness.


No. It is called "random sampling without replacement".
It is still random; you are simply reducing the population
with each selection -- just like dealing cards from a
shuffled deck.

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
Seed numbers for random number generation, uniform distribution darebo Excel Discussion (Misc queries) 3 April 21st 23 09:02 PM
Random Numbers anuterrnd Excel Worksheet Functions 1 July 22nd 05 05:32 AM
random numbers from a data of numbers? MaryEng Excel Worksheet Functions 6 May 31st 05 12:09 PM
Validating random numbers plsauditor Excel Worksheet Functions 2 January 11th 05 11:12 PM
generate random numbers Jules Excel Worksheet Functions 6 November 2nd 04 05:57 PM


All times are GMT +1. The time now is 04:20 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"