Commit a9b3ecf5 authored by Him188's avatar Him188

Improve getRandomByteArray

parent ff6403cd
@file:Suppress("MemberVisibilityCanBePrivate") @file:Suppress("MemberVisibilityCanBePrivate", "unused")
package net.mamoe.mirai.message package net.mamoe.mirai.message
......
...@@ -15,6 +15,8 @@ import java.util.zip.CRC32 ...@@ -15,6 +15,8 @@ import java.util.zip.CRC32
import java.util.zip.GZIPInputStream import java.util.zip.GZIPInputStream
import java.util.zip.GZIPOutputStream import java.util.zip.GZIPOutputStream
import javax.imageio.ImageIO import javax.imageio.ImageIO
import kotlin.random.Random
import kotlin.random.nextInt
/** /**
...@@ -93,11 +95,7 @@ fun DataInputStream.skip(n: Number) { ...@@ -93,11 +95,7 @@ fun DataInputStream.skip(n: Number) {
this.skip(n.toLong()) this.skip(n.toLong())
} }
fun getRandomByteArray(length: Int): ByteArray { fun getRandomByteArray(length: Int): ByteArray = List(length) { Random.Default.nextInt(0..255).toByte() }.toByteArray()
val bytes = LinkedList<Byte>()
repeat(length) { bytes.add((Math.random() * 255).toByte()) }
return bytes.toByteArray()
}
operator fun File.plus(child: String): File = File(this, child) operator fun File.plus(child: String): File = File(this, child)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment