Problem written by Chris Piech
Worked Examples: E=MC2, Fibbonacci, Carbon Dating
This problem starts with a sad story. When I was growing up in Kenya it was estimated that over 38% of medicines sold at pharmacies were fake [1]. That was a big problem! Depending on which organization you ask, deaths from counterfeit medicine ranged from 100,000 per year (WHO) to 700,000 (IPN) [2].
Deaths from counterfeit drugs are equivalent to, "four fully laden jumbo jets crashing everyday" [2]
In 2009 a Ghanaian fellow named Bright Simmons came up with a straightforward technology solution he called mPedigree. He partnered with companies that make medicine. On each legitimate package of medicine they stamped a unique scratch code. Now when you buy medicine at a pharmacy in Kenya you check the scratch code and text message mPedigree. If the code is in their system, and has never been used before, mPedigree sends a text message back saying: "valid." There has been a 58% decrease in child deaths from Malaria alone [3]. Sometimes simple programming solutions can have a large, positive impact on the world.
Write a program that generates 10-digit numbers for 1,000 packages of medicine. Each number you generate should be (1) unique and (2) unpredictable.
Here is a screenshot from an example execution:
Those numbers will be put on medicine packages. Counterfeiters won't stand a chance!
To generate random numbers create a RandomGenerator instance variable (a variable declared outside all methods) like so:
private RandomGenerator rgen = new RandomGenerator();
You can then use the variable to generate random numbers.
rgen.nextInt(min, max) // generates a random int in the range (min, max) inclusive
That's all! Ask questions if you don't understand something (or want to know more about counterfeit medicine)