zoukankan      html  css  js  c++  java
  • 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());

    }


    }


  • 相关阅读:
    CentOS6 install Ruby 1.9.3
    php注释规范
    ecstore小记
    关于local storage 和 session storage以及cookie 区别简析
    local storage 简单应用‘’记住密码’
    点击按钮播放音频 停止后再次点击再次播放 添加背景音乐
    页面触底自动加载数据
    侧导航下载
    解决ie对于Bootstrap的兼容性问题
    js判断微信 选择浏览器打开
  • 原文地址:https://www.cnblogs.com/james1207/p/3303882.html
Copyright © 2011-2022 走看看