Get started

nextByteString

Creates a byte string of the specified size, filled with random bytes.

Throws

Samples

import kotlinx.io.bytestring.*
import kotlin.random.Random
import kotlin.test.*

fun main() { 
   //sampleStart 
   val a = Random.nextByteString(4)
println(a.toHexString())
val b = Random.nextByteString(4)
println(b.toHexString())
// These are two distinct byte strings
assertNotEquals(a, b)

assertEquals(0, Random.nextByteString(0).size)

assertFailsWith<IllegalArgumentException> { Random.nextByteString(-42)  } 
   //sampleEnd
}