TDHooligan

typewrter

Nov 7th, 2025 (edited)
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.67 KB | None | 0 0
  1. -- monkey_typewriter.lua
  2. math.randomseed(os.time())
  3.  
  4. -- characters the "monkey" can type
  5. local chars = {}
  6. for i = 32, 126 do  -- printable ASCII range
  7.     table.insert(chars, string.char(i))
  8. end
  9.  
  10. -- function to get a random character
  11. local function random_char()
  12.     return chars[math.random(#chars)]
  13. end
  14.  
  15.  
  16. -- main typing loop
  17. while true do
  18.     local num = math.random() * 3 + 1
  19.     if math.random(1, 40) == 1 then
  20.         io.write("\n")
  21.     end
  22.     for i=1, num do
  23.         io.write(random_char())
  24.         sleep(0.05)
  25.         io.flush()
  26.     end
  27.     -- random short delay between keystrokes
  28.     local delay = math.random() * 0.5+0.3  -- between 0 and 0.1 seconds
  29.     sleep(delay)
  30. end
Advertisement
Add Comment
Please, Sign In to add comment