package com.tzld.piaoquan.growth.common.utils;

import java.util.Random;

/**
 * 验证码生成器
 *
 * @author sunxy
 */
public class VerificationCodeGenerator {
    public static void main(String[] args) {
        String verificationCode = generateVerificationCode(6);
        System.out.println("Six-digit Verification Code: " + verificationCode);
    }

    public static String generateVerificationCode(int length) {
        if (length <= 0) {
            throw new IllegalArgumentException("Length should be a positive integer.");
        }

        Random random = new Random();
        StringBuilder codeBuilder = new StringBuilder();

        for (int i = 0; i < length; i++) {
            int digit = random.nextInt(10); // 生成0到9之间的随机数字
            codeBuilder.append(digit);
        }

        return codeBuilder.toString();
    }
}
