Returns random binary blob.

        Default blob size is 1 Mb.
424434
def binary(self, length=(1 * 1024 * 1024)):
        
        blob = [self.generator.random.randrange(256) for _ in range(length)]
        return bytes(blob) if sys.version_info[0] >= 3 else bytearray(blob)
1283004
def asBinary(self):
        
        binString = binary.bin(self._value)[2:]
        return '0' * (len(self._value) - len(binString)) + binString
1100857
def random_unit(size=3):
    
    while True:
        result = np.random.normal(0, 1, size)
        length = np.linalg.norm(result)
        if length > 1e-3:
            return result/length
15700
def crc24(blob):
    """"""
    CRC24_INIT = 0x0B704CE
    CRC24_POLY = 0x1864CFB

    crc = CRC24_INIT
    for octet in bytearray(blob):
        crc ^= (octet << 16)
        for _ in range(8):
            crc <<= 1
            if crc & 0x1000000:
                crc ^= CRC24_POLY
    assert 0 <= crc < 0x1000000
    crc_bytes = struct.pack('>L', crc)
    assert crc_bytes[:1] == b'\x00'
    return crc_bytes[1:]
409956
def fetch_blob(cls, username, password, multifactor_password=None, client_id=None):
        """"""
        session = fetcher.login(username, password, multifactor_password, client_id)
        blob = fetcher.fetch(session)
        fetcher.logout(session)

        return blob
21776
def _image_of_size(image_size):
  """"""
  return np.random.uniform(0, 256, [image_size, image_size, 3]).astype(np.uint8)
594644
def get_nonzero_random_bytes(length, rnd=default_crypto_random):
    '''
       
    '''
    result = []
    i = 0
    while i < length:
        rnd = rnd.getrandbits(12*length)
        s = i2osp(rnd, 3*length)
        s = s.replace('\x00', '')
        result.append(s)
        i += len(s)
    return (''.join(result))[:length]
225608
def read(self, size=None):
        """"""
        blob = self.s.read(size)
        if size is not None and len(blob) < size:
            raise EOFError
        if self._captured:
            self._captured.write(blob)
        return blob
463232
def corrupt_bytes(s, p=0.01, n=None):
    """"""
    s = array.array("B", bytes_encode(s))
    s_len = len(s)
    if n is None:
        n = max(1, int(s_len * p))
    for i in random.sample(range(s_len), n):
        s[i] = (s[i] + random.randint(1, 255)) % 256
    return s.tostring() if six.PY2 else s.tobytes()
1342077
function randomHexString(size) {
  if (size === 0) {
    throw new Error('Zero-length randomHexString is useless.');
  }
  if (size % 2 !== 0) {
    throw new Error('randomHexString size must be divisible by 2.');
  }
  return crypto.randomBytes(size / 2).toString('hex');
}
1042090
function _bnToBytes(b) {
  // prepend 0x00 if first byte >= 0x80
  var hex = b.toString(16);
  if(hex[0] >= '8') {
    hex = '00' + hex;
  }
  return forge.util.hexToBytes(hex);
}
1299926
def random_hash(size=9999999999, hash_type=None):
    '''
    
    '''
    if not hash_type:
        hash_type = 'md5'
    hasher = getattr(hashlib, hash_type)
    return hasher(salt.utils.stringutils.to_bytes(six.text_type(random.SystemRandom().randint(0, size)))).hexdigest()
63533
public function fileSize($size, bool $binary = true): string
	{
		if($size > 0)
		{
			if($binary === true)
			{
				$base  = 1024;
				$terms = ['byte', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
			}
			else
			{
				$base  = 1000;
				$terms = ['byte', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
			}

			$e = floor(log($size, $base));

			return round($size / ($base ** $e), 2) . ' ' . $terms[$e];
		}

		return '0 byte';
	}
1070939
def random_hex(length):
    """"""
    return escape.to_unicode(binascii.hexlify(os.urandom(length))[length:])
151803
def get_net_size(mask):
    '''
    
    '''
    binary_str = ''
    for octet in mask.split('.'):
        binary_str += bin(int(octet))[2:].zfill(8)
    return len(binary_str.rstrip('0'))
1081803
def randomBinaryField(self):
        
        lst = [
            b"hello world",
            b"this is bytes",
            b"awesome django",
            b"djipsum is awesome",
            b"\x00\x01\x02\x03\x04\x05\x06\x07",
            b"\x0b\x0c\x0e\x0f"
        ]
        return self.randomize(lst)
635345
public static byte[] randomBytes(int size) {
        byte[] bytes = new byte[size];

        for (int index = 0; index < size; index++) {
            bytes[index] = (byte) randomNumber(0, 255);
        }

        return bytes;
    }