I took inspiration from a challenge I did some years ago in a programming competition.

Your goal is to write a function that generates a random integer number between 0 and 150 (included), and then prints it in actual words. For example, 139 would be printed as onehundredthirtynine.


  • You cannot use any external resource, nor any library that will perform the conversion.

  • The shortest answer will win.

Good luck!

  • \$\begingroup\$ With or without spaces? \$\endgroup\$
    – ProgramFOX
    Jan 2, 2014 at 18:53
  • \$\begingroup\$ Without spaces, as you can see in the example! :) \$\endgroup\$
    – Vereos
    Jan 2, 2014 at 18:54
  • \$\begingroup\$ ... Damn, I actually searched for it. Didn't use proper keywords :/ \$\endgroup\$
    – Vereos
    Jan 2, 2014 at 18:57
  • 1
    \$\begingroup\$ Don't worry, neither I found it easily. (I knew another question which links to that one.) \$\endgroup\$
    – manatwork
    Jan 2, 2014 at 19:00

1 Answer 1




Highly optimized and golfed xkcd's random number generator

An actual solution, 380

x=math.random(0,150)m=math.floor print(x==0 and"zero"or((x>99 and"onehundred"or"")..(({"ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"})[x%100-9]or({[0]="",nil,"twenty","thirty","fourty","fifty","sixty","seventy","eighty","ninety"})[m(x/10)%10]..({[0]="","one","two","three","four","five","six","seven","eight","nine"})[x%10])))

Not the answer you're looking for? Browse other questions tagged or ask your own question.