Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10
Default Random Numbers and Me

Hey!

I´m having a little problem generating a few random numbers. The thing is
this: I have a huge list of people and I need to assign a random number
between 0.0 and 1.25 to each one.

The problem is I need the following:

70% of people to have a number between 1 and 1.2
20% of people to have a number greater than 1.2
10% of people to have a number below 1

Do you know how to do this???

Thanks!!
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,501
Default Random Numbers and Me

not another one
--
Mike

When competing hypotheses are equal, adopt the hypothesis that introduces
the fewest assumptions while still sufficiently answering the question.
Occam''s razor (Abbrev)


"John Pivot Table" wrote:

Hey!

I´m having a little problem generating a few random numbers. The thing is
this: I have a huge list of people and I need to assign a random number
between 0.0 and 1.25 to each one.

The problem is I need the following:

70% of people to have a number between 1 and 1.2
20% of people to have a number greater than 1.2
10% of people to have a number below 1

Do you know how to do this???

Thanks!!

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,934
Default Random Numbers and Me

Give the following macro a try; it will distribute the values in the three ranges randomly among the names (as opposed to assigning them to the same names each time as Mike's code does). In addition, Mike was correct about not always being able to apply the 70/20/10 rule perfectly (you would need the number of names to be a multiple of 10 for that to happen).... my code forces the 10% and 20% numbers (always rounded up at the percentage works out to a half a person or more) with the remainder of the count being approximately 70%). The only thing you need to do in the code is set the 3 Const values to their correct values for your particular layout (I assumed that the first name was in Row 2 with Row 1 being an assumed header; that the names were in Column A and the output column for the random numbers was Column B).

Sub Randoms()
Static RanBefore As Boolean
Dim TempElement As Single, RndNums() As Single
Dim X As Long, NameCount As Long, LastNamesRow As Long
Const FirstNamesRow As Long = 2
Const NamesColumn As String = "A"
Const RandNumColumn As String = "B"
' Make sure Randomize is executed only once per session
If Not RanBefore Then
RanBefore = True
Randomize
End If
LastNamesRow = Cells(Rows.Count, NamesColumn).End(xlUp).Row
NameCount = LastNamesRow - FirstNamesRow + 1
ReDim RndNums(1 To NameCount)
' Assign the number of random numbers for each range
For X = 1 To Format(0.1 * NameCount, "0")
RndNums(X) = Rnd
Next
For X = Format(0.1 * NameCount, "0") + 1 To Format(0.3 * NameCount, "0")
RndNums(X) = 0.15 * Rnd + 1.20001
Next
For X = Format(0.3 * NameCount, "0") + 1 To NameCount
RndNums(X) = 0.2 * Rnd + 1
Next
' Randomize those assignments within the array
For X = NameCount To 1 Step -1
RandomIndex = Int((X - LBound(RndNums) + 1) * Rnd + LBound(RndNums))
TempElement = RndNums(RandomIndex)
RndNums(RandomIndex) = RndNums(X)
RndNums(X) = TempElement
Next
' Assign those randomized numbers to the names
For X = 1 To NameCount
Cells(FirstNamesRow, RandNumColumn).Offset(X - 1) = RndNums(X)
Next
End Sub

--
Rick (MVP - Excel)


"John Pivot Table" wrote in message ...
Hey!

I´m having a little problem generating a few random numbers. The thing is
this: I have a huge list of people and I need to assign a random number
between 0.0 and 1.25 to each one.

The problem is I need the following:

70% of people to have a number between 1 and 1.2
20% of people to have a number greater than 1.2
10% of people to have a number below 1

Do you know how to do this???

Thanks!!

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,501
Default Random Numbers and Me

Hmmmm,

A very good point, my solution does assign random numbers to the same groups
each time. If i was to improve it i would populate a column with a random
number, do a sort and then apply my random numbers to the randomely sorted
list of names.
--
Mike

When competing hypotheses are equal, adopt the hypothesis that introduces
the fewest assumptions while still sufficiently answering the question.
Occam''s razor (Abbrev)


"Rick Rothstein" wrote:

Give the following macro a try; it will distribute the values in the three ranges randomly among the names (as opposed to assigning them to the same names each time as Mike's code does). In addition, Mike was correct about not always being able to apply the 70/20/10 rule perfectly (you would need the number of names to be a multiple of 10 for that to happen).... my code forces the 10% and 20% numbers (always rounded up at the percentage works out to a half a person or more) with the remainder of the count being approximately 70%). The only thing you need to do in the code is set the 3 Const values to their correct values for your particular layout (I assumed that the first name was in Row 2 with Row 1 being an assumed header; that the names were in Column A and the output column for the random numbers was Column B).

Sub Randoms()
Static RanBefore As Boolean
Dim TempElement As Single, RndNums() As Single
Dim X As Long, NameCount As Long, LastNamesRow As Long
Const FirstNamesRow As Long = 2
Const NamesColumn As String = "A"
Const RandNumColumn As String = "B"
' Make sure Randomize is executed only once per session
If Not RanBefore Then
RanBefore = True
Randomize
End If
LastNamesRow = Cells(Rows.Count, NamesColumn).End(xlUp).Row
NameCount = LastNamesRow - FirstNamesRow + 1
ReDim RndNums(1 To NameCount)
' Assign the number of random numbers for each range
For X = 1 To Format(0.1 * NameCount, "0")
RndNums(X) = Rnd
Next
For X = Format(0.1 * NameCount, "0") + 1 To Format(0.3 * NameCount, "0")
RndNums(X) = 0.15 * Rnd + 1.20001
Next
For X = Format(0.3 * NameCount, "0") + 1 To NameCount
RndNums(X) = 0.2 * Rnd + 1
Next
' Randomize those assignments within the array
For X = NameCount To 1 Step -1
RandomIndex = Int((X - LBound(RndNums) + 1) * Rnd + LBound(RndNums))
TempElement = RndNums(RandomIndex)
RndNums(RandomIndex) = RndNums(X)
RndNums(X) = TempElement
Next
' Assign those randomized numbers to the names
For X = 1 To NameCount
Cells(FirstNamesRow, RandNumColumn).Offset(X - 1) = RndNums(X)
Next
End Sub

--
Rick (MVP - Excel)


"John Pivot Table" wrote in message ...
Hey!

I´m having a little problem generating a few random numbers. The thing is
this: I have a huge list of people and I need to assign a random number
between 0.0 and 1.25 to each one.

The problem is I need the following:

70% of people to have a number between 1 and 1.2
20% of people to have a number greater than 1.2
10% of people to have a number below 1

Do you know how to do this???

Thanks!!

.

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
getting numbers divisible by 4 from random numbers in ascending order ramana Excel Worksheet Functions 6 June 19th 07 06:41 PM
How to select top six numbers from a of range of random numbers Jack M Taylor Excel Worksheet Functions 4 January 30th 07 09:18 PM
Can Excel pick random numbers from 1-300 and not repeat numbers? Julian Excel Discussion (Misc queries) 1 June 7th 06 07:17 AM
Non-random numbers generated by excel's data analysis random gener Allie Excel Worksheet Functions 10 September 17th 05 06:19 AM
Non-random numbers generated by excel's data analysis random gener Harlan Grove Excel Discussion (Misc queries) 2 September 13th 05 04:06 PM


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