dakomeah Posted October 18, 2010 Share Posted October 18, 2010 Hi Everybody, Pls i would like to develop an algorithm to generate pin codes which will be used for making scratch cards for commercializing certain services on a website. I would like to know if there is any material anywhere, that i can read to guide me, or anyone who has handled such a project before can put me in the right direction. The specifications are. It must be a 14 digit code, Generated Non sequentially, However there much be a way of validating it, as different pin codes will be generated for different regions, such that a pin code bought in one region can only be used in making queries about only that region, and not any other. Thank you Quote Link to comment Share on other sites More sharing options...
upp Posted November 19, 2010 Share Posted November 19, 2010 you could generate random numbers between certain values for certain regions. example region a will have numbers between 10000000000000 and 19999999999999, region b will have a random number between 20000000000000 and 29999999999999, and so on.... then you could apply a switch and figure out what region they are in. example: $region = "north"; // put the region of the user here switch($region){ case "north": $pin = rand(10000000000000, 19999999999999); break; case "south": $pin = rand(20000000000000, 29999999999999); break; } switch($pin){ case ($pin >= 10000000000000 && $pin <= 19999999999999): echo "you are in the north"; break; case ($pin >= 20000000000000 && $pin <= 29999999999999): echo "you are in the south"; break; } Quote Link to comment Share on other sites More sharing options...
Wildbug Posted November 19, 2010 Share Posted November 19, 2010 Credit card companies use the Luhn algorithm. I know different companies start their numbers with different prefixes, so you could adapt something similar to attach codes to regions. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.