From 1cf88d43994ec7ec403319032a9d118b39fe3571 Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期五, 25 四月 2025 14:35:35 +0800 Subject: [PATCH] 登录代码优化 --- pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/CreateRadom.java | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 117 insertions(+), 0 deletions(-) diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/CreateRadom.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/CreateRadom.java new file mode 100644 index 0000000..aeb5ee2 --- /dev/null +++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/CreateRadom.java @@ -0,0 +1,117 @@ +package com.dy.common.util; + +import java.util.Random; + +public class CreateRadom { + + public static int radom(int max, int min){ + return new Random().nextInt(max) % (max - min + 1) + min; + } + + public static void main(String[] args) { + System.out.println(CreateRadom.radom(1, 0)); + System.out.println(CreateRadom.radom(2, 0)); + System.out.println(CreateRadom.radom(3, 0)); + System.out.println(CreateRadom.radom(4, 0)); + System.out.println(CreateRadom.radom(5, 0)); + System.out.println(CreateRadom.radom(100, 0)); + System.out.println(CreateRadom.radom(1256, 1234)); + } + + /** + * 4浣嶉殢鏈烘暟鎹� + * @return 闅忔椂鏁� + */ + public static int radom_4(){ + return new Random().nextInt(9999) % (9999 - 1000 + 1) + 1000; + } + /** + * 5浣嶉殢鏈烘暟鎹� + * @return 闅忔椂鏁� + */ + public static int radom_5(){ + return new Random().nextInt(99999) % (99999 - 10000 + 1) + 10000; + } + /** + * 6浣嶉殢鏈烘暟鎹� + * @return 闅忔椂鏁� + */ + public static int radom_6(){ + return new Random().nextInt(999999) % (999999 - 100000 + 1) + 100000; + } + + + /** + * 鍒涘缓scape浣嶉殢鏈烘暟 + * @return 闅忔椂鏁� + */ + public String create(int scape){ + if(scape < 1){ + scape = 6 ; + } + double d = Math.random(); + String s = String.valueOf(d); + int index; + String ss; + try{ + index = s.indexOf('.') + 1; + ss = s.substring(index , index + scape); + } catch(Exception e){ + ss = "740414"; + } + return ss ; + } + + /** + * 鍒涘缓涓や釜鏁存暟涔嬮棿鐨勯殢鏈烘暟 + * @param min 鏈�灏忓�� + * @param max 鏈�澶у�� + * @return 闅忔椂鏁� + */ + public static int create_between(int min , int max){ + if(max < min){ + return min ; + } + if(max - min < min/2){ + return min ; + } + String mins = String.valueOf(min) ; + int len = mins.length() ; + char minfirst = mins.charAt(0) ; + double d = Math.random(); + d = d * 10000000 ; + String s = String.valueOf(d); + s = minfirst + s ; + s = s.substring(0 ,len) ; + int n = Integer.parseInt(s) ; + if(n < min || n > max){ + n = create_between(min , max) ; + } + return n ; + } + + + /** + * 寰楀埌涓�涓皬浜巑ax鐨勯殢鏈烘暟 + * @param max int 鏈�澶у�� + * @return int 闅忔椂鏁� + */ + public int create_less(int max){ + if(max > 9){ + max = 9 ; + } + double d = Math.random(); + int n = 0 ; + int m; + String s = String.valueOf(d); + for(int i = 4 ; i < s.length() ; i++){ + m = Integer.parseInt(s.charAt(i)+""); + if(m < max){ + n = m ; + break ; + } + } + return n ; + } + +} -- Gitblit v1.8.0