SDG/Config/IronPython.Credit Card Numbers.xml

<?xml version="1.0" encoding="Windows-1252"?><generators><generator type="RedGate.SQLDataGenerator.ExpressionGenerators.Python.PythonScriptGenerator" name="Credit Card Number (VISA)" description="Valid VISA style credit card numbers (using IronPython)" category="Payment">
<property name="Code"># Generate VISA-style numbers with a Luhn checksum
 
import clr
clr.AddReference("System")
from System import Random
random = Random()
 
def choice(l):
    return l[random.Next(len(l))]
 
def completed_number(prefix, length):
    # Given a prefix and a desired length, fill in the number up
    # to the desired length, using Luhn to compute the checksum
    ccnumber = list(prefix)
 
    # Generate digits
    for _ in range(length - len(prefix) - 1):
        ccnumber.append(choice('0123456789'))
 
    # Calculate sum
    sum = pos = 0
    reversedCCnumber = list(reversed(ccnumber))
    while pos &lt; length - 1:
        odd = int(reversedCCnumber[pos]) * 2
        if odd &gt; 9: odd -= 9
        if pos != (length - 2): sum += int(reversedCCnumber[pos+1])
        sum += odd
        pos += 2
 
    # Calculate check digit
    checkdigit = ((sum / 10 + 1) * 10 - sum) % 10
    ccnumber.append(str(checkdigit))
     
    return ''.join(ccnumber)
 
def main(config):
    for _ in range(config["n_rows"]):
        # VISA numbers start with a 4
        yield completed_number('4', 16)
</property>
 
<property name="ColumnType">nvarchar</property>
<type sqlType="NVarchar" type="String" /></generator></generators>