<commit_before>
export const randomId = () => {
  return "1234"; //TODO
}

export const randomSecret = () => {
  return "1234"; //TODO
}<commit_msg>Fill in RNG functions under webpack<commit_after>import * as _ from 'underscore';

// Excludes 0O1lIUV
const unmistakableChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTWXYZ23456789";

export const randomId = () => {
  if (webpackIsServer) {
    const crypto = require('crypto');
    const bytes = crypto.randomBytes(17);
    const result = [];
    for (let byte of bytes) {
      // Discards part of each byte and has modulo bias. Doesn't matter in
      // this context.
      result.push(unmistakableChars[byte % unmistakableChars.length]);
    }
    return result.join('');
  } else {
    const result = [];
    function randInt(max) {
      return Math.floor(Math.random() * max);
    }
    for (let i=0; i<17; i++)
      result.push(unmistakableChars[randInt(unmistakableChars.length)]);
    return result.join('');
  }
}

export const randomSecret = () => {
  if (webpackIsServer) {
    const crypto = require('crypto');
    return crypto.randomBytes(15).toString('base64');
  } else {
    throw new Error("No CSPRNG available on the client");
  }
}

console.log(`Sample randomId: ${randomId()}`);
console.log(`Sample randomSecret: ${randomSecret()}`);
{'fraction_non_alphanumeric': 0.14416475972540047, 'fraction_numerical': 0.020594965675057208, 'mean_word_length': 3.652482269503546, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 7, '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': '3307566', 'n_tokens_mistral': 457, 'n_tokens_neox': 417, 'n_words': 104}