#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 99
Default Random Number

There is a function that allows you to select Random Numbers
=randbetween(1,25). This function is available when you add in the Analysis
Toolpak. The problem is that if I copy it over cells it does sometimes
repeat a number. I only want unique numbers can anyone help with this one,
maybe there is another way of getting only unique numbers to appear
--
Wendy
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,327
Default Random Number

Hi Wendy

I don't think I've seen a pure formula solution to this one. For unique
numbers, you need a list of all those numbers and then pick a random
selection from it. Like
A1:A25 contains numbers 1 to 25
B1:B25 contains formula =RAND()
Sort by B column.

HTH. Best wishes Harald

"Wendy" skrev i melding
...
There is a function that allows you to select Random Numbers
=randbetween(1,25). This function is available when you add in the

Analysis
Toolpak. The problem is that if I copy it over cells it does sometimes
repeat a number. I only want unique numbers can anyone help with this

one,
maybe there is another way of getting only unique numbers to appear
--
Wendy



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,593
Default Random Number

Here is a formual solution, with a twist.

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$25,B1)=1)) ,B1,RANDBETWEEN(1,25))
it should show a 0

Copy B1 down to B25.

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 B25, and re-input A1.


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Harald Staff" wrote in message
...
Hi Wendy

I don't think I've seen a pure formula solution to this one. For unique
numbers, you need a list of all those numbers and then pick a random
selection from it. Like
A1:A25 contains numbers 1 to 25
B1:B25 contains formula =RAND()
Sort by B column.

HTH. Best wishes Harald

"Wendy" skrev i melding
...
There is a function that allows you to select Random Numbers
=randbetween(1,25). This function is available when you add in the

Analysis
Toolpak. The problem is that if I copy it over cells it does sometimes
repeat a number. I only want unique numbers can anyone help with this

one,
maybe there is another way of getting only unique numbers to appear
--
Wendy





  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 136
Default Random Number

Hello Wendy,

I suggest to take my function UniqRandInt:
http://www.sulprobil.com/html/uniqrandint.html

HTH,
Bernd

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 266
Default Random Number

"Wendy" skrev i en meddelelse
...
There is a function that allows you to select Random Numbers
=randbetween(1,25). This function is available when you add in the
Analysis
Toolpak. The problem is that if I copy it over cells it does sometimes
repeat a number. I only want unique numbers can anyone help with this
one,
maybe there is another way of getting only unique numbers to appear
--
Wendy


Hi Wendy

Here's an UDF(UserDefinedFunction).
If you select 25 cells the numbers 1 through 25 are inserted
at random in the cells. If you select 15 cells, numbers 1 -15
are inserted etc.
From the workbook this is accomplished thus:

1. Select the range
2. While the cells are selected enter the formula
=myrand()
3. Finish with <Shift<Ctrl<Enter instead of just <Enter

If you want to start with the number 10 instead of 1 enter

=myrand(10)

to start with -10 instead of 1 enter

=myrand(-10)

etc.

To get a new set of values press <Ctrl<Alt<F9.


Insert the below function in a general module.


Function MyRand(Optional RandOffset As Long) As Variant
'Leo Heuser, 2 August, 2006
Dim Counter As Long
Dim Counter1 As Long
Dim NumOfElements As Long
Dim Placement As Long
Dim Result() As Variant
Dim RandColumns As Long
Dim RandData() As Variant
Dim RandRows As Long

Randomize

With Range(Application.Caller.Address)
RandRows = .Rows.Count
RandColumns = .Columns.Count
End With

NumOfElements = RandRows * RandColumns

If RandOffset = 0 Then RandOffset = 1

ReDim RandData(1 To NumOfElements)

For Counter = 1 To NumOfElements
RandData(Counter) = Counter + (RandOffset - 1)
Next Counter

ReDim Result(1 To RandRows, 1 To RandColumns)

For Counter = 1 To RandRows
For Counter1 = 1 To RandColumns
Placement = Int(Rnd() * NumOfElements + 1)
Result(Counter, Counter1) = RandData(Placement)
RandData(Placement) = RandData(NumOfElements)
NumOfElements = NumOfElements - 1
Next Counter1
Next Counter

MyRand = Result

End Function



--
Best regards
Leo Heuser

Followup to newsgroup only please.



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
same number appears in a random number generator Carmel Excel Worksheet Functions 4 May 28th 06 12:22 AM
Random Number generator Neil M Excel Worksheet Functions 2 February 1st 06 06:00 PM
Random letter and number generator Marie1uk Excel Worksheet Functions 4 January 23rd 06 06:04 PM
random number generation scotjo Excel Worksheet Functions 4 January 9th 06 04:06 PM
Random Number Questions Greegan Excel Worksheet Functions 1 January 5th 05 02:00 AM


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