How to randomly generate eight-digit discount codes and save them to Mysql database
This article is about how to randomly generate eight-digit discount codes and save them to the Mysql database. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
At present, many businesses do activities through the discount code, and now we simply achieve the eight-digit discount code and save it in the database.
1. The randomly generated discount code is as follows:
Import java.util.Random;/*** function: randomly generate discount codes * @ author iamwiam**/public class Activatedcode {public int ACTIVATEDCODENUM = 200; / / number of generated discount codes Random random = new Random (); String candicatedCode = "abcedefghijklmnopqrstuvwxyz"; / / discount codes contain lowercase letters candicatedCode+=candicatedCode.toUpperCase () / / the discount code contains the uppercase letters candicatedCode+= "1234567890"; / / the discount code contains the Arabic numerals for (int item0; I < ACTIVATEDCODENUM;i++) {String res = ""; for (int job0witj)