Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 86
Default Rand between 1 and 50

I have a lottery worksheet to design which will produce 6 unique numbers
between 1 and 50 in six cells.
I use =INT(RAND()*51) at the moment which works well. How do I alter this
function so that 0 does not appear as one of the numbers?
--
Thank you,

Colin.
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 63
Default Rand between 1 and 50

=INT(RAND()*50) + 1

--
met vriendelijke groetjes

"Colin" schreef in bericht
...
I have a lottery worksheet to design which will produce 6 unique numbers
between 1 and 50 in six cells.
I use =INT(RAND()*51) at the moment which works well. How do I alter this
function so that 0 does not appear as one of the numbers?
--
Thank you,

Colin.



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,420
Default Rand between 1 and 50

Try

=INT((RAND()*50+1))

--
__________________________________
HTH

Bob

"Colin" wrote in message
...
I have a lottery worksheet to design which will produce 6 unique numbers
between 1 and 50 in six cells.
I use =INT(RAND()*51) at the moment which works well. How do I alter this
function so that 0 does not appear as one of the numbers?
--
Thank you,

Colin.



  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8,651
Default Rand between 1 and 50

=RANDBETWEEN(1,50) but neither that nor your formula will ensure that the
numbers are unique.
--
David Biddulph

"Colin" wrote in message
...
I have a lottery worksheet to design which will produce 6 unique numbers
between 1 and 50 in six cells.
I use =INT(RAND()*51) at the moment which works well. How do I alter this
function so that 0 does not appear as one of the numbers?
--
Thank you,

Colin.



  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,501
Default Rand between 1 and 50

Colin,

There are no VB ways of getting unique randoms within a range but here's a
VB solution you may consider, right click your sheet tab view code and paste
this in and run it. It will put 6 unique numbers in columnA

Sub Lottry_Randoms()
Dim MyRange As Range
Set MyRange = Range("A1:A6")
For Each c In MyRange
Do
c.Value = Int((50 * Rnd) + 1)
Loop Until WorksheetFunction.CountIf(MyRange, c.Value) < 2
Next
End Sub

Mike

"Colin" wrote:

I have a lottery worksheet to design which will produce 6 unique numbers
between 1 and 50 in six cells.
I use =INT(RAND()*51) at the moment which works well. How do I alter this
function so that 0 does not appear as one of the numbers?
--
Thank you,

Colin.



  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,501
Default Rand between 1 and 50

There are no VB ways of getting unique randoms

Which should have been There are non VB ways.......

"Mike H" wrote:

Colin,

There are no VB ways of getting unique randoms within a range but here's a
VB solution you may consider, right click your sheet tab view code and paste
this in and run it. It will put 6 unique numbers in columnA

Sub Lottry_Randoms()
Dim MyRange As Range
Set MyRange = Range("A1:A6")
For Each c In MyRange
Do
c.Value = Int((50 * Rnd) + 1)
Loop Until WorksheetFunction.CountIf(MyRange, c.Value) < 2
Next
End Sub

Mike

"Colin" wrote:

I have a lottery worksheet to design which will produce 6 unique numbers
between 1 and 50 in six cells.
I use =INT(RAND()*51) at the moment which works well. How do I alter this
function so that 0 does not appear as one of the numbers?
--
Thank you,

Colin.

  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 86
Default Rand between 1 and 50


Thank you for all your responses,

Colin.


"Mike H" wrote:

There are no VB ways of getting unique randoms


Which should have been There are non VB ways.......

"Mike H" wrote:

Colin,

There are no VB ways of getting unique randoms within a range but here's a
VB solution you may consider, right click your sheet tab view code and paste
this in and run it. It will put 6 unique numbers in columnA

Sub Lottry_Randoms()
Dim MyRange As Range
Set MyRange = Range("A1:A6")
For Each c In MyRange
Do
c.Value = Int((50 * Rnd) + 1)
Loop Until WorksheetFunction.CountIf(MyRange, c.Value) < 2
Next
End Sub

Mike

"Colin" wrote:

I have a lottery worksheet to design which will produce 6 unique numbers
between 1 and 50 in six cells.
I use =INT(RAND()*51) at the moment which works well. How do I alter this
function so that 0 does not appear as one of the numbers?
--
Thank you,

Colin.

  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 99
Default Rand between 1 and 50

Hi Colin,

I do this (not for lottery numbers but the concept is the same), by putting
=RAND() in A1 and copying down to A50.
Then in B1, put =MATCH(SMALL($A$1:$A$50,ROW()),$A$1:$A$50,0) and copy down
to B6.
You can then hide column A if you like.

There is a very small possiblity of duplicates, but I've never had that arise.

Dave




"Colin" wrote:


Thank you for all your responses,

Colin.


"Mike H" wrote:

There are no VB ways of getting unique randoms


Which should have been There are non VB ways.......

"Mike H" wrote:

Colin,

There are no VB ways of getting unique randoms within a range but here's a
VB solution you may consider, right click your sheet tab view code and paste
this in and run it. It will put 6 unique numbers in columnA

Sub Lottry_Randoms()
Dim MyRange As Range
Set MyRange = Range("A1:A6")
For Each c In MyRange
Do
c.Value = Int((50 * Rnd) + 1)
Loop Until WorksheetFunction.CountIf(MyRange, c.Value) < 2
Next
End Sub

Mike

"Colin" wrote:

I have a lottery worksheet to design which will produce 6 unique numbers
between 1 and 50 in six cells.
I use =INT(RAND()*51) at the moment which works well. How do I alter this
function so that 0 does not appear as one of the numbers?
--
Thank you,

Colin.

  #9   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,420
Default Rand between 1 and 50

To Mike H

First, ensure cell 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$10,B1)=1)) ,B1,INT(RAND()*10+1))
it should show a 0

Copy B1 down to B10.

Finally, put some value in A1, say an 'x', and all the random numbers will
be generated, and 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 B10, and re-input A1.

--
__________________________________
HTH

Bob

"Mike H" wrote in message
...
There are no VB ways of getting unique randoms


Which should have been There are non VB ways.......

"Mike H" wrote:



  #10   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,501
Default Rand between 1 and 50

Bob,

Interesting, thank you.


Mike

"Bob Phillips" wrote:

To Mike H

First, ensure cell 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$10,B1)=1)) ,B1,INT(RAND()*10+1))
it should show a 0

Copy B1 down to B10.

Finally, put some value in A1, say an 'x', and all the random numbers will
be generated, and 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 B10, and re-input A1.

--
__________________________________
HTH

Bob

"Mike H" wrote in message
...
There are no VB ways of getting unique randoms


Which should have been There are non VB ways.......

"Mike H" wrote:






  #11   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 806
Default Rand between 1 and 50

Hello Colin,

Select 6 cells and array-enter
UniqRandInt(50)

My UDF UniqRandInt you can find he
http://www.sulprobil.com/html/uniqrandint.html

Regards,
Bernd
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
how can i set up rand or rand between to give only -1 or 1? Uesiet Excel Worksheet Functions 8 October 27th 08 02:28 PM
=INT(0+(1-0+1)*RAND()) wtf? Robert Blass Excel Worksheet Functions 4 October 11th 08 05:27 AM
RAND() Dave F Excel Discussion (Misc queries) 4 October 24th 06 08:15 PM
help for RAND jinvictor Excel Worksheet Functions 3 May 13th 06 12:13 AM
RAND() ScottC Excel Discussion (Misc queries) 2 May 1st 05 12:37 PM


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