• java实现点卡生成


    点卡主要有2部分:卡号和密码。卡号一般由数字组成,密码就不多说了。


    java中随机数很强大,大家可以自己查。卡号生成使用java中随机数,密码使用uuid,密码可以自己再加点东西之类的。下面是完整代码:

    public class TimeCard {


    private static String getFixLenthString(int strLength) {  
         
       Random rm = new Random();  
         
       // 获得随机数  
       double pross = (1 + rm.nextDouble()) * Math.pow(10, strLength);  
     
       // 将获得的获得随机数转化为字符串  
       String fixLenthString = String.valueOf(pross);  
     
       // 返回固定的长度的随机数  ,如果随机数前面有“.”,把2调大。
       return fixLenthString.substring(2, strLength + 1);  
    }  

    private static String getUUID(){ 
            String s = UUID.randomUUID().toString(); 
            //去掉“-”符号 
            return s.substring(0,8)+s.substring(9,13)+s.substring(14,18)+s.substring(19,23)+s.substring(24); 
        } 

    /**
    * 卡号N位随机数
    * 卡密用uuid,不够再加几位随机数
    * 存入数据库
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub


    int num = 10;//点卡数目
    ITimeCard tc = new TimeCardDAO();

    for(int i = 0;i<num;i++){ 
    tc.addTimeCard(getFixLenthString(18), getUUID());//给数据库添加记录
    try {
    Thread.sleep(5);
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
       System.out.println(getFixLenthString(18));  
       System.out.println(getUUID());

    }


    }


  • 相关阅读:
    hdu 2.2.4 Wolf and Rabbit 解题心得
    概率(经典问题) 解题心得
    POJ2250:Compromise(LCS) 解题心得
    POJ 3903 Stock Exchange 解题心得
    2015 HUAS Summer Trainning #5~E
    2015 HUAS Summer Trainning #5~A
    015 HUAS Summer Contest#3~A
    2015 HUAS Summer Trainning #4~B
    2015 HUAS Summer Contest#3~E
    2015 HUAS Summer Contest#3~B
  • 原文地址:https://www.cnblogs.com/james1207/p/3303882.html
Copyright © 2020-2023  润新知