Luhn algorithm is the commonly used logic to produce the checksum of credit card number which is the last number of the long series of numbers.
The code below generates a valid Luhn algorithm Visa credit card number that start with the number 4. Explanation of the algorithm is in the comment.