Skip to content

Instantly share code, notes, and snippets.

@nozma
Last active August 16, 2017 15:08
Show Gist options
  • Select an option

  • Save nozma/ac256c1476b2757a279e6aabccb01ea0 to your computer and use it in GitHub Desktop.

Select an option

Save nozma/ac256c1476b2757a279e6aabccb01ea0 to your computer and use it in GitHub Desktop.
# coding: utf-8
import numpy.random as rd
def gen_typo(S):
if len(S) <= 4:
return S
else:
idx = [0]
idx.extend(rd.choice(range(1, len(S)-1), len(S)-2, replace=False))
idx.append(len(S)-1)
result = []
for i in range(len(S)):
result.append(S[idx[i]])
return ''.join(result)
s = "I couldn't believe that I could actually understand what I was reading : the phenomenal power of the human mind ."
s = s.split()
print(' '.join([gen_typo(i) for i in s]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment