# Write some Random English

Given an odd integer input n greater than 1, generate a random English word of length n. An English word is one in which the odd (1-based) indices are consonants and the even (1-based) indices are vowels, the vowels being aeiou.

## Random

For the purposes of this challenge, you are to sample from the vowels and consonants uniformly, with replacement. In other words, each possible English word must be equally likely to appear as an output.

# Example Inputs/Outputs

3 -> bab, tec, yiq
5 -> baron, nariz, linog
7 -> murovay, fanafim


Winner:

Winner is the Lowest Byte Count.

Upvote your Favorite one, Top 3 Upvoted will be Honorable Mentions :P

• Welcome to the site. I don't really understand the challenge here. Maybe the sandbox (linked on the right), would be a good place to get feedback. Feb 7, 2020 at 19:19
• Are we making a function that generates the words? Or should the program simply generate them when run? Feb 7, 2020 at 19:49
• Hi there. I've voted to close this as needing additional clarity, but do not fret when this gets closed! It's tough to get a challenge specified up to our standards the first few times you come up with one, so we have a sandbox for you to get feedback on them before they come to the main site. Hope you enjoy your time here, and happy golfing! Feb 7, 2020 at 20:46
• Be sure to specify what you mean by random. Also, how is the output size specified? Is it also random? Feb 7, 2020 at 21:35
• I've gone ahead and edited it (and voted to re-open), please make edits to it as you feel appropriate! Feb 12, 2020 at 19:19

# 05AB1E, 14 11 bytes

-3 bytes thanks to Kevin Cruijssen

EžN¸žMšNèΩJ


Try it online!

• ¸ì can be š, .R can be Ω, and the } can be removed before the join. Feb 10, 2020 at 7:49
• oh wow, thank you! @KevinCruijssen Feb 10, 2020 at 9:07

# Vyxals, 9 bytes

⟑₂¨ikvk¹℅


Try it online!

Explanation:

⟑          # Map over the range 1 to n
₂¨i       # If even:
kv     #   Push the string "aeiou"
# Otherwise:
k¹   #   Push the lowercase consonants
℅  # Get a random character from the top of the stack
# Concatenate the character list into a string with the s flag


# Perl 5, 69 bytes

say map{([a,e,i,o,u],[grep!/[eiou]/,b..z])[$_%2][rand$_%2*16+5]}1..<>


Try it online!

# Stax, 10 bytes

ÇÅφ⌠↑Ñ°↕Yx


Run and debug it

# Explanation

FVcVv2l@_@L

F           In range 1 to the input, do this ...
Vv         Vowels
Vc       Consonants
2l     Wrap the two inside a list
@    Index the constructed list into the counter
Note that the counter starts at 1,
so this picks the constants list
before the vowels list.
_@  Index by the current counter
(Stax doesn't have random number support)
L Wrap the whole stack into a list

• Wow, nice job on this one Feb 13, 2020 at 12:17

# Ruby, 76 bytes

Basic recursive function that adds a consonant and a vowel each time until there's only one character left, at which point it adds just the consonant.

f=->n{[*?b..?z].grep(/[^eiou]/).sample+(n<2?'':'aeiou'.chars.sample+f[n-2])}


Try it online!

# GolfScript, 36 bytes

,{['aeiou'.123,97>^]\2%=.,rand=}%''+


Try it online!

• You can save some bytes by using ['aeiou'.123,97>^] instead of your long string. Generates the characters 98-123, then removes the vowels. Plus, they're in two distinct arrays too, which saves you a bunch too. the string and 21/ can be removed, meaning you're down 31 chars and up 18, netting 13. ,{['aeiou'.123,97>^]\2%=.,rand=}%''+ This worked for me. Feb 14, 2020 at 14:18

# Pip, 12 bytes

RC*[.CZVW]Ha


Try It Online!

### Explanation

This should be 11 bytes; the . is a no-op to work around a bug in the current language version.

RC*[CZVW]Ha
[    ]    List containing:
CZ         Lowercase consonants
VW       Lowercase vowels
a  Command-line argument
H   Take that many elements (cycling the list as necessary)
RC*          Random choice from each


I also found several 13-byte solutions:

RC{VW::CZ}M,a
RC[CZVW]@_M,a
LaORC(VW::CZ)


## D, 124 bytes

auto f(int n){string s;for(import std;n;n--,s~=n%2?"aeiou"[uniform(0,5)]:"bcdfghjklmnpqrstvwxyz"[uniform(0,20)]){}return s;}


I'm not very good at code golf (but trying to get better) so this can probably be improved a lot

Try it online

• Welcome to Code Golf, and nice first answer! Unfortunately we don't have a Tips for Golfing in D page, but it's nice to see someone using a language not regularly used on our site! Sep 2 at 8:35
• You might want to add a Try it online link so others can test your code. Note: I don't know D and I'm probably doing this wrong. Sep 2 at 9:43
• Golfed off a few bytes. Idk what the issue with garbage bytes being appended is... Sep 2 at 9:55
• Unfortunately you can't rely on counting backwards since the vowels/consonants will swap depending on the parity of the input. You can fix this by changing s~=... to s=...~s. You can also combine the strings and indexing for 112 bytes
– Jo King
Sep 2 at 11:58
• the issue with garbage characters was since you were using cast(char*) to convert to a C string when passing to printf. you have to use toStringz (or the better solution is just to use the write/writeln function from std.stdio) Sep 4 at 5:48

# Python, 83 bytes

lambda n:[*map(choice,["bcdfghjklmnpqrstvwxzy","aeiou"]*n)][:n]
from random import*


Attempt This Online!

Outputs a list of characters.

This is conceptually the same as grc's answer for "Generate a pronounceable word", since the questions are almost identical.

# Factor + pair-rocket sequences.repeating, 62 bytes

[ "bcdfghjklmnpqrstvwxyz"=> "aeiou"swap cycle [ random ] map ]


Attempt This Online!

                                   ! 5
"bcdfghjklmnpqrstvwxyz"=> "aeiou"  ! 5 { "bcdfghjklmnpqrstvwxyz" "aeiou" }
swap                               ! { "bcdfghjklmnpqrstvwxyz" "aeiou" } 5
cycle                              ! { "bcdfghjklmnpqrstvwxyz" "aeiou" "bcdfghjklmnpqrstvwxyz" "aeiou" "bcdfghjklmnpqrstvwxyz" }
[ random ] map                     ! "furom"


# Bash, 93 89 bytes

v=aeiou]
until tr -dc a-z</dev/urandom|head -c$1|grep -E "^[^$v([$v[^$v)*[$v?$";do
:
done


Try it online!

A full command line program.

It generates random lowercase alpha strings of the required size in a loop until we find one matching the pattern ^<vowel>(<cons><vowel>)*<cons>?.

# JavaScript (Node.js), 89 bytes

f=(n,b)=>(b?"aeiou":"bcdfghjklmnpqrstvwyxz")[~~(Math.random()*(b?5:21))]+(--n?f(n,!b):"")


Try it online! (includes tests)

Takes n as length and b as whether to return vowel or consonant, default consonant.

Returns consonant or vowel based on b, decrements n and recurses with opposite b value.