6

For an application we are working on I need to generate sample credit card numbers which pass the Luhn algorithm but which are also unique, so we cannot use the sample credit card numbers.

We need to be able to generate around 300 card numbers at a time, and ideally i would be able to do this when generating my input data.

Many Thanks

John Weldon
  • 39,849
  • 11
  • 94
  • 127
Kev Hunter
  • 2,565
  • 4
  • 25
  • 39

5 Answers5

9

Create random numbers, then calculate the checksum number.

You can find more information at Wikipedia - Luhn, both details about the algorithm and links to different implementations.

sisve
  • 19,501
  • 3
  • 53
  • 95
3

From what I see you just need to ensure that when running through the algorithm you get a result of 0 (mod 10). So you can pick any number of random digits (or sequential if you like) and just add one last digit which will ensure that the number is valid.

Joey
  • 344,408
  • 85
  • 689
  • 683
2

I took the code from Graham Kings site and ported it to c#, also emailing Graham a copy, you can find it here link text

Kev Hunter
  • 2,565
  • 4
  • 25
  • 39
  • The latest version of c# port can be found on [GitHub](https://github.com/grahamking/darkcoding-credit-card/blob/master/CreditCardNumberGenerator.cs) – Michael Freidgeim Jun 01 '16 at 21:24
2

Do you need the credit card #'s to pass any other tests? i.e. should they look like valid VISA, MasterCard, or AMEX, etc.

If so, you may want a resource like Graham King's otherwise some of the other suggestions here are good.

The latest version of Graham King's generator (including c# code) can be found on GitHub.

Michael Freidgeim
  • 26,542
  • 16
  • 152
  • 170
John Weldon
  • 39,849
  • 11
  • 94
  • 127
1

If you need a list to test each card, you'll find one here. How to test credit card interactions?

Community
  • 1
  • 1
Mike
  • 5,181
  • 3
  • 25
  • 19