Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Randon Date Generator Help Please

Status
Not open for further replies.

Billab123

Programmer
May 13, 2012
2
AU
Hi,

I am trying to write a code that will give a random group of 23 people,how likely is it that two people have the same birthday. i need to write a program that creates a random date array from 1 to 23 (being the number of people) and to assign each of the 23 people a random date integer from 1 to 365 the program needs to check all the dates to see if theres are any matching dates and to be repated 100 times for how many matching birthdays there would be and i need the answer to be around 50 to 60%.

so far i have got a code that will randomly display a date but im not to sure on the rest would some one be able to help me out
thanks

this is the code i have so far


Sub GenerateRandomNumberInRange()
Dim MaxNumber As Integer
Dim MinNumber As Integer
Dim RandomNumber As Integer
MinNumber = 1
MaxNumber = 365
RandomNumber = Int((Rnd * (MaxNumber - MinNumber + 1)) + MinNumber)
Debug.Print DateSerial(1983, 1, RandomNumber)
'
msg = DateSerial(1983, 1, RandomNumber)
MsgBox msg
End Sub
 
Please note that this OP (as liked by macropod), has asked this question twice, and appears to have ignored responses.

Gerry
 
> i need the answer to be around 50 to 60%

No, you don't.

That'll be the proposition that you are testing for.
 
Oh, and you need to run it a lot more than 100 times in order to get a result close to the statistical answer
 

i need the answer to be around 50 to 60%

Then forget the whole age stuff and run this 100 times:

Code:
MsgBox  Int((Rnd * (60 - 50 + 1)) + 50)

Have fun.

---- Andy
 
andrezjek were do i put that in the code?

i put it in the last line is that right?

Sub GenerateRandomNumberInRange()
Dim MaxNumber As Integer
Dim MinNumber As Integer
Dim RandomNumber As Integer
MinNumber = 1
MaxNumber = 365
RandomNumber = Int((Rnd * (MaxNumber - MinNumber + 1)) + MinNumber)
Debug.Print DateSerial(1983, 1, RandomNumber)
'
msg = DateSerial(1983, 1, RandomNumber)
MsgBox Int((Rnd * (60 - 50 + 1)) + 50)
End Sub

but its just displaying 1 random number like 53 insted of a date how do i fix this?
 

but its just displaying 1 random number like 53 insted of a date
DateSerial returns a NUMBER, that you can then FORMAT to return a date...
Code:
msg = DateSerial(1983, 1, RandomNumber)
MsgBox format(msg, "yyyy/mm/dd")


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 

Acting in a reckless manner causes entropy to increase in the universe.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
oops! Don't know how THAT got in here!!!???

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I think you need to first realize that there are 365^23 different possibilities of birthdays for these 23 people. Of that, there are 365!/[(365-2)(2!)] different combinations where 2 people have the same birthday. I think you're being VERY optimistic if you think you'll find them in 100 runs.
 
Sadly, Zelgar, you have fallen in to a common misconception. This is called the birthday paradox, and the odds that two people in a group of 23 share the same birthday is about 50%. Billab123 is just looking to modek this to prove the conjecture.
 

I was sarcastic when I gave you this piece of code. I should be more clear with :) or something. That’s because you stated “i need the answer to be around 50 to 60%”, then just get the random numbers between 50 and 60. And you cannot do that: assume what the number will be and make it so.

That's also what strongm said: "That'll be the proposition that you are testing for. "

Have fun.

---- Andy
 
macropod, I meant LINKED. You put two links to the posts in the other forum.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top