no message

This commit is contained in:
2026-02-05 11:42:52 +08:00
parent f2ee83ca64
commit a5a532bc82
90 changed files with 7945 additions and 2458 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2025 mingliqiye
* Copyright 2026 mingliqiye
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,15 +16,13 @@
* ProjectName mingli-utils
* ModuleName mingli-utils.main
* CurrentFile RandomBytes.kt
* LastUpdate 2025-09-16 17:42:26
* LastUpdate 2026-01-28 10:47:13
* UpdateUser MingLiPro
*/
@file:JvmName("RandomBytes")
package com.mingliqiye.utils.random
import java.security.SecureRandom
/**
* 生成指定长度的随机字节数组
* @param length 数组长度
@@ -38,6 +36,7 @@ fun randomBytes(length: Int): ByteArray {
return bytes
}
/**
* 生成指定长度的随机字节数组
* 从给定的字节数组中随机选择字节来填充新数组
@@ -81,12 +80,8 @@ fun randomByteNoHave(from: Byte, to: Byte): Byte {
return (randomValue and 0xFF).toByte()
}
val secureRandom: SecureRandom by lazy {
SecureRandom.getInstanceStrong()
}
fun randomByteSecure(size: Int): ByteArray {
fun randomByte(size: Int): ByteArray {
val bytes = ByteArray(size)
secureRandom.nextBytes(bytes)
return bytes
@@ -1,5 +1,5 @@
/*
* Copyright 2025 mingliqiye
* Copyright 2026 mingliqiye
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,14 +16,24 @@
* ProjectName mingli-utils
* ModuleName mingli-utils.main
* CurrentFile RandomInt.kt
* LastUpdate 2025-09-12 17:08:32
* LastUpdate 2026-01-28 10:46:02
* UpdateUser MingLiPro
*/
@file:JvmName("RandomInt")
package com.mingliqiye.utils.random
import java.util.concurrent.ThreadLocalRandom
import java.security.SecureRandom
val secureRandom: SecureRandom by lazy {
SecureRandom.getInstanceStrong()
}
fun SecureRandom.nextInt(min: Int, max: Int): Int {
return min + nextInt(max - min)
}
/**
* 生成指定范围内的随机整数
@@ -42,7 +52,7 @@ fun randomIntNoHave(min: Int, max: Int): Int {
if (min == max) {
return min
}
return ThreadLocalRandom.current().nextInt(min, max)
return secureRandom.nextInt(min, max)
}
/**
@@ -55,6 +65,3 @@ fun randomInt(min: Int, max: Int): Int {
var max = max
return randomIntNoHave(min, ++max)
}
@@ -1,5 +1,5 @@
/*
* Copyright 2025 mingliqiye
* Copyright 2026 mingliqiye
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
* ProjectName mingli-utils
* ModuleName mingli-utils.main
* CurrentFile RandomString.kt
* LastUpdate 2025-09-12 17:10:43
* LastUpdate 2026-02-05 11:12:36
* UpdateUser MingLiPro
*/
@file:JvmName("RandomString")