<commit_before>(ns caesium.randombytes
  "Utilities for producing cryptographically random bytes, suitable
  for use as a key or other input entropy."
  (:require [caesium.binding :refer [sodium]]
            [caesium.byte-bufs :refer [buflen]])
  (:import (java.nio ByteBuffer)))

(defn random-to-byte-array!
  "**DANGER** This function is low-level, you only want to use it if you are
  managing your own buffers. See [[randombytes]] for a high level API that
  creates the byte array buffer for you.

  Given a byte array, populate it with n random bytes.

  If n is not given, populates the entire array."
  ([^bytes arr]
   (random-to-byte-array! arr (buflen arr)))
  ([^bytes arr n]
   (.randombytes sodium arr (long n))
   arr))

(defn random-to-byte-buffer!
  "**DANGER** This function is low-level, you only want to use it if you are
  managing your own buffers. See [[randombytes]] for a high level API that
  creates the byte array buffer for you.

  Given a byte buffer, populate it with n random bytes.

  If n is not given, populates the entire buffer."
  ([^ByteBuffer buf]
   (random-to-byte-buffer! buf (.remaining buf)))
  ([^ByteBuffer buf n]
   (.randombytes sodium buf (long n))
   buf))

(defn randombytes
  "Create a byte array with n random bytes."
  [n]
  (let [buf (byte-array n)]
    (random-to-byte-array! buf n)))<commit_msg>Fix docstring<commit_after>(ns caesium.randombytes
  "Utilities for producing cryptographically random bytes, suitable
  for use as a key or other input entropy."
  (:require [caesium.binding :refer [sodium]]
            [caesium.byte-bufs :refer [buflen]])
  (:import (java.nio ByteBuffer)))

(defn random-to-byte-array!
  "**DANGER** This function is low-level, you only want to use it if you are
  managing your own buffers. See [[randombytes]] for a high level API that
  creates the byte array buffer for you.

  Given a byte array, populate it with n random bytes.

  If n is not given, populates the entire array."
  ([^bytes arr]
   (random-to-byte-array! arr (buflen arr)))
  ([^bytes arr n]
   (.randombytes sodium arr (long n))
   arr))

(defn random-to-byte-buffer!
  "**DANGER** This function is low-level, you only want to use it if you are
  managing your own buffers. See [[randombytes]] for a high level API that
  creates the buffer for you.

  Given a byte buffer, populate it with n random bytes.

  If n is not given, populates the entire buffer."
  ([^ByteBuffer buf]
   (random-to-byte-buffer! buf (.remaining buf)))
  ([^ByteBuffer buf n]
   (.randombytes sodium buf (long n))
   buf))

(defn randombytes
  "Create a byte array with n random bytes."
  [n]
  (let [buf (byte-array n)]
    (random-to-byte-array! buf n)))
{'fraction_non_alphanumeric': 0.10901001112347053, 'fraction_numerical': 0.0, 'mean_word_length': 3.466887417218543, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7192209', 'n_tokens_mistral': 873, 'n_tokens_neox': 844, 'n_words': 366}