Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
Select your favorite languages :
  • Or search :

Idiom #310 Fill array with random bytes

Fill the byte array a with randomly generated bytes.

import "math/rand"
rand.Read(a)
import "crypto/rand"
_, err := rand.Read(a)
for b in a do b := random(256);
import random
a[:] = random.randbytes(len(a))
import random
a = random.randbytes(N)
require 'securerandom'
a = SecureRandom.random_bytes(a.length)

New implementation...
< >
programming-idioms.org