EDN Admin
Well-known member
With the information Ive found from the birthday paradox, Im trying to make a calculator similar to
http://jeff.aaron.ca/cgi-bin/birthday" target="_blank this but I cannot seem to figure out how to get a real number. The factorial of 365! gives an overflow. But its not just VB, even my TI-84 Plus Silver Edition calculator gives
an overflow as the number is so high.
What data types can I use to get numbers as high as "365!"? Is there anyway I can get an accurate answer for the birthday paradox calculator in VB.NET?
<div style="color:black; background-color:white
<pre><span style="color:green Option Strict On
<span style="color:blue Public <span style="color:blue Class Form1
<span style="color:blue Private <span style="color:blue Function BirthdayParadox(<span style="color:blue ByVal people <span style="color:blue As <span style="color:blue Integer) <span style="color:blue As <span style="color:blue String
<span style="color:green P(A) prime
<span style="color:blue Dim birthday <span style="color:blue As <span style="color:blue Decimal
birthday = <span style="color:blue CDec((Factorial(365) / (Factorial(365 - people) * Math.Pow(365, people))))
<span style="color:blue Dim output <span style="color:blue As <span style="color:blue Decimal
output = (1 - birthday)
<span style="color:blue Return output.ToString()
<span style="color:blue End <span style="color:blue Function
<span style="color:blue Public <span style="color:blue Function Factorial(<span style="color:blue ByVal Number <span style="color:blue As <span style="color:blue Decimal) <span style="color:blue As <span style="color:blue Decimal
<span style="color:blue If Number = 0 <span style="color:blue Then
<span style="color:blue Return 1
<span style="color:blue Else
<span style="color:blue Return Number * Factorial(Number - 1)
<span style="color:blue End <span style="color:blue If
<span style="color:blue End <span style="color:blue Function
<span style="color:blue Private <span style="color:blue Sub Button1_Click(sender <span style="color:blue As System.Object, e <span style="color:blue As System.EventArgs) <span style="color:blue Handles Button1.Click
Label1.Text = BirthdayParadox(TextBox1.Text)
<span style="color:blue End <span style="color:blue Sub
<span style="color:blue End <span style="color:blue Class
[/code]
<br/>
Thanks,
- Jordan
<
<span style="color:green If you find an answer helpful, click the Helpful button. If you find an answer to your question, mark it as the answer.<br/>
http://www.metasdevelopment.com www.metasdevelopment.com Jordan St. Godard | Microsoft Community Contributor 2011
Helpful Links:<br/>
<span style="font-style:normal http://alturl.com/g82uc Visual Basic for Applications (VBA)
<span style="font-style:normal http://alturl.com/abgfc Visual Basic 6 (VB6)
<span style="font-style:normal http://alturl.com/43h8o Visual Basic Script (VBS)
<span style="font-style:normal http://alturl.com/yyuex Convert C# to VB
<br/>
<br/>
http://www.metasdevelopment.com <img src="http://alturl.com/cwvdb" alt="
<br/>
View the full article
http://jeff.aaron.ca/cgi-bin/birthday" target="_blank this but I cannot seem to figure out how to get a real number. The factorial of 365! gives an overflow. But its not just VB, even my TI-84 Plus Silver Edition calculator gives
an overflow as the number is so high.
What data types can I use to get numbers as high as "365!"? Is there anyway I can get an accurate answer for the birthday paradox calculator in VB.NET?
<div style="color:black; background-color:white
<pre><span style="color:green Option Strict On
<span style="color:blue Public <span style="color:blue Class Form1
<span style="color:blue Private <span style="color:blue Function BirthdayParadox(<span style="color:blue ByVal people <span style="color:blue As <span style="color:blue Integer) <span style="color:blue As <span style="color:blue String
<span style="color:green P(A) prime
<span style="color:blue Dim birthday <span style="color:blue As <span style="color:blue Decimal
birthday = <span style="color:blue CDec((Factorial(365) / (Factorial(365 - people) * Math.Pow(365, people))))
<span style="color:blue Dim output <span style="color:blue As <span style="color:blue Decimal
output = (1 - birthday)
<span style="color:blue Return output.ToString()
<span style="color:blue End <span style="color:blue Function
<span style="color:blue Public <span style="color:blue Function Factorial(<span style="color:blue ByVal Number <span style="color:blue As <span style="color:blue Decimal) <span style="color:blue As <span style="color:blue Decimal
<span style="color:blue If Number = 0 <span style="color:blue Then
<span style="color:blue Return 1
<span style="color:blue Else
<span style="color:blue Return Number * Factorial(Number - 1)
<span style="color:blue End <span style="color:blue If
<span style="color:blue End <span style="color:blue Function
<span style="color:blue Private <span style="color:blue Sub Button1_Click(sender <span style="color:blue As System.Object, e <span style="color:blue As System.EventArgs) <span style="color:blue Handles Button1.Click
Label1.Text = BirthdayParadox(TextBox1.Text)
<span style="color:blue End <span style="color:blue Sub
<span style="color:blue End <span style="color:blue Class
[/code]
<br/>
Thanks,
- Jordan
<
<span style="color:green If you find an answer helpful, click the Helpful button. If you find an answer to your question, mark it as the answer.<br/>
http://www.metasdevelopment.com www.metasdevelopment.com Jordan St. Godard | Microsoft Community Contributor 2011
Helpful Links:<br/>
<span style="font-style:normal http://alturl.com/g82uc Visual Basic for Applications (VBA)
<span style="font-style:normal http://alturl.com/abgfc Visual Basic 6 (VB6)
<span style="font-style:normal http://alturl.com/43h8o Visual Basic Script (VBS)
<span style="font-style:normal http://alturl.com/yyuex Convert C# to VB
<br/>
<br/>
http://www.metasdevelopment.com <img src="http://alturl.com/cwvdb" alt="
<br/>
View the full article