Win a copy of Penetration Testing Basics this week in the Security forum!

# Dereferencing error

Nicole Doetsch
Greenhorn
Posts: 6
I keep getting a dereferencing error on a program that I have to write pertaining to the "Birthday Paradox"

I understand that int is a primitive type, but I'm not sure how to make it dereferencable.

My code is below and I hope someone could help me clear up this problem!

Ralph Cook
Ranch Hand
Posts: 479
You cannot dereference a primitive type. Whatever code you wanted to be run as your method isDuplicate(), it cannot be a method on int.

Perhaps what you meant to do was calculate a birthdate and store it in a separate int variable, then determine if the array at that int position had already been visited.

dennis deems
Ranch Hand
Posts: 808
Your code looks like it is trying to combine three different strategies into one procedure. You have an array birthDates of size 365 which suggests you mean each index to represent a day in the year. Then you pull this value named "people" out of thin air and use that as the array index. You randomly write an int value to the array. Then you call a method that takes no parameter and returns no value, but apparently is meant to evaluate whether the random value you just cooked up is a duplicate. However, it's actually looking at an element in the array and determining whether that element is equal to itself.

I recommend you use pencil and paper and work out how you would perform this task without a computer. You may actually have done so on the first day of a statistics course. Write out that process. Don't imagine you are writing instructions for a computer. Imagine you are writing instructions for a person to read. Write it out in simple language, so that someone could understand who had never taken statistics and doesn't know what the Birthday Paradox is. When you have a set of instructions so simple and exact that this is the case, you'll be ready to start writing code.

Campbell Ritchie
Sheriff
Posts: 50624
82
What’s the birthday paradox? Is it that you have a >50% chance of two people having the same birthday if you have a population of ≥23?