jiro4989 / faker

Faker is a Nim package that generates fake data for you.
https://jiro4989.github.io/faker/faker.html
MIT License
42 stars 8 forks source link

fake username #71

Open enthus1ast opened 2 years ago

enthus1ast commented 2 years ago

with "default" rules, like:

user.name
FooBaa
jiro4989 commented 2 years ago

What do you want?

Do you want the name procedure that always returns only FooBaa with default ?

Or, do you want the name procedure that always returns FooBaa with default too?

enthus1ast commented 2 years ago

i meant usernames normally looks like:

FirstLast
First.Last
F1rstL4st     <---- l33t speak would also be a nice addition btw
F.Last
DoRaMa   <---- combinations of Phonetic "fitting" letters like: ra ma da ri im en 

Digraph Frequency

th he an in er on re ed nd ha at en es of nt ea ti to io le is ou ar as de rt ve

Trigraph Frequency

the and tha ent ion tio for nde has nce tis oft men

enthus1ast commented 2 years ago

i've played around a little, i will eventually put this in my fork here is the code for you to play around :)

import strutils, random, tables
const di = "th he an in er on re ed nd ha at en es of nt ea ti to io le is ou ar as de rt ve".split(" ")
const tri = "the and tha ent ion tio for nde has nce tis oft men".split(" ")

randomize()

const leetAlphabet = {
  "a" : """4, /-\, /_\, @, /\, Д, а""".replace(" ", "").split(","),
  "b" : """8, |3, 13, |}, |:, |8, 18, 6, |B, |8, lo, |o, j3, ß, в, ь""".replace(" ", "").split(","),
  "c" : """<, {, [, (, ©, ¢, с""".replace(" ", "").split(","),
  "d" : """|), |}, |], |>""".replace(" ", "").split(","),
  "e" : """3, £, ₤, €, е""".replace(" ", "").split(","),
  "f" : """7, |=, ph, |#, |", ƒ""".replace(" ", "").split(","),
  "g" : """[, -, [+, 6, C-""".replace(" ", "").split(","),
  "h" : """#, 4, |-|, [-], {-}, }-{, }{, |=|, [=], {=}, /-/, (-), )-(, :-:, I+I, н""".replace(" ", "").split(","),
  "i" : """1, |, !, 9""".replace(" ", "").split(","),
  "j" : """_|, _/, _7, 9,[1] _), _], _}""".replace(" ", "").split(","),
  "k" : """|<, 1<, l<, |{, l{""".replace(" ", "").split(","),
  "l" : """|_, |, 1, ][""".replace(" ", "").split(","),
  "m" : """44, |\/|, ^^, /\/\, /X\, []\/][, []V[], ][\\//][, (V), //., .\\, N\, м""".replace(" ", "").split(","),
  "n" : """|\|, /\/, /V, ][\\][, И, и, п""".replace(" ", "").split(","),
  "o" : """0, (), [], {}, <>, Ø, oh, Θ, о, ө""".replace(" ", "").split(","),
  "p" : """|o, |O, |>, |*, |°, |D, /o, []D, |7, р""".replace(" ", "").split(","),
  "q" : """O_, 9, (,), 0, kw""".replace(" ", "").split(","),
  "r" : """|2, 12, .-, |^, l2, Я, ®""".replace(" ", "").split(","),
  "s" : """5, $, §""".replace(" ", "").split(","),
  "t" : """7, +, 7`, т""".replace(" ", "").split(","),
  "u" : """ú, ü""".replace(" ", "").split(","),
  "v" : """\/""".replace(" ", "").split(","),
  "w" : """\/\/, (/\), \^/, \\', '//, VV, Ш""".replace(" ", "").split(","),
  "x" : """%, *, ><, }{, )(, Ж""".replace(" ", "").split(","),
  "y" : """`/, ¥, \|/, Ч, ү, у""".replace(" ", "").split(","),
  "z" : """5, 7_, >_, (/)""".split(",")
}.toTable()

proc leet(str: string, chance = 1): string =
  for ch in str:
    if rand(100) < chance:
      result.add leetAlphabet[($ch).toLower()].sample()
    else:
      result.add ch

proc capitalize(str: string, chance = 15): string =
    if rand(100) < chance:
      result.add str.capitalizeAscii()
    else:
      result.add str

proc gen(): string =
  var hasDot = false
  for idx in 0..(rand(3) + 1):
    case rand(3)
    of 0:
      result.add sample(di).capitalize()
    of 1:
      result.add sample(tri).capitalize()
    of 2:
      result.add sample(di).leet().capitalize()
    else:
      result.add sample(tri).leet().capitalize()
    if not hasDot:
      if rand(100) < 5:
        hasDot = true
        result.add "."

for idx in 0..10:
  echo gen()

which can generate usernames/nicknames like this:

TioTiIon
HasIsOftat
EstisEdEnt
MenrtAn
haDe
Tioerthe
DemenEntAn
Outhe
HasVence
theReen
IonIonFor
Thend
rtOftHas
ontis
arionndeded
deve.menofis
ncehandTio
formenand
oftisen
entfor
iontisndetiotio
ent.ndas
fishnibble commented 1 year ago

@enthus1ast Have you made a PR for this?