[Question]
  [
Given an input string, output that string with all vowels `a`, `e`, `i`, `o` and `u` swapped at random between each other.
For example, in the string `this is a test`, there are 4 vowels: `[i, i, a, e]`. A valid shuffling of those vowels could be `[a, i, e, i]` therefore yielding the output `thas is e tist`.
### About shuffling
All shuffles shall be equally likely **if we consider equal vowels to be distinct**. For the example above, those 24 shuffles are possible:
```
[i1, i2, a, e]    [i1, i2, e, a]    [i1, a, i2, e]    [i1, a, e, i2]
[i1, e, i2, a]    [i1, e, a, i2]    [i2, i1, a, e]    [i2, i1, e, a]
[i2, a, i1, e]    [i2, a, e, i1]    [i2, e, i1, a]    [i2, e, a, i1]
[a, i1, i2, e]    [a, i1, e, i2]    [a, i2, i1, e]    [a, i2, e, i1]
[a, e, i1, i2]    [a, e, i2, i1]    [e, i1, i2, a]    [e, i1, a, i2]
[e, i2, i1, a]    [e, i2, a, i1]    [e, a, i1, i2]    [e, a, i2, i1]
```
Each one should be equally as likely.
You may not try random shuffles of the entire string until finding one where all vowels are in the right place. In short, your code's running time shall be constant if the input is constant.
### Inputs and outputs
* You may assume that all letters in the input will be lowercase or uppercase. You may also support mixed casing, though this won't give you any bonus.
* The input will always consist of printable ASCII characters. All characters that are in the input shall be in the output, only the vowels must be shuffled around and nothing else.
* The input can be empty. There is no guarantee that the input will contain at least one vowel or at least one non-vowel.
* You may take the input from `STDIN`, as a function parameter, or anything similar.
* You may print the output to `STDOUT`, return it from a function, or anything similar.
### Test cases
The first line is the given input. The second line is one of the possible outputs.
```
<empty string>
<empty string>
a
a
cwm
cwm
the quick brown fox jumps over the lazy dog.
tho qeuck brewn fax jumps ovir the lozy dog.
abcdefghijklmnopqrstuvwxyz
abcdefghujklmnipqrstovwxyz
programming puzzles & code golf
pregromming pezzlos & coda gulf
fatalize
fitaleza
martin ender
mirten ander
```
### Scoring
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), *sa tho shirtist enswer en bytes wons*.
  
[Answer]
## R, 92 91
Can't comment yet so I'm adding my own answer albeit very similar to @Andreï Kostyrka answer (believe it or not but came up with it independently).
```
s=strsplit(readline(),"")[[1]];v=s%in%c("a","e","i","o","u");s[v]=sample(s[v]);cat(s,sep="")
```
### Ungolfed
```
s=strsplit(readline(),"")[[1]]    # Read input and store as a vector
v=s%in%c("a","e","i","o","u")     # Return TRUE/FALSE vector if vowel
s[v]=sample(s[v])                 # Replace vector if TRUE with a random permutation of vowels
cat(s,sep="")                     # Print concatenated vector
```
---
Saved one byte thanks to @Vlo
```
s=strsplit(readline(),"")[[1]];s[v]=sample(s[v<-s%in%c("a","e","i","o","u")]);cat(s,sep="")
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 15 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
f€“¡ẎṢɱ»ðœpżFẊ¥
```
[Try it online!](http://jelly.tryitonline.net/#code=ZuKCrOKAnMKh4bqO4bmiybHCu8OwxZNwxbxG4bqKwqU&input=&args=dGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZy4)
### How it works
```
f€“¡ẎṢɱ»ðœpżFẊ¥  Main link. Argument: s (string)
  “¡ẎṢɱ»         Yield "aeuoi"; concatenate "a" with the dictionary word "euoi".
f€               Filter each character in s by presence in "aeuoi".
                 This yields A, an array of singleton and empty strings.
        ð        Begin a new, dyadic chain. Left argument: A. Right argument: s
         œp      Partition s at truthy values (singleton strings of vowels) in A.
            FẊ¥  Flatten and shuffle A. This yields a permutation of the vowels.
           ż     Zip the partition of consonants with the shuffled vowels.
```
[Answer]
# R, ~~99~~ ~~98~~ 89 bytes
```
x=el(strsplit(readline(),""))
z=grepl("[aeiou]",x)
x[z]=x[sample(which(z))]
cat(x,sep="")
```
Seems to be the first human-readable solution! Thanks to [Giuseppe](https://codegolf.stackexchange.com/users/67312/giuseppe) for saving 9 bytes!
Test cases:
```
tho qaeck bruwn fux jemps over tho lozy dig.
progremmang pozzlos & cide gulf
```
Seems that there is no way to make an internal variable assignment (inside, like, `cat`), and again some people are going to prove I am wrong...
[Answer]
## CJam, 23 bytes
```
lee_{"aeiou"&},_mrerWf=
```
[Try it online!](http://cjam.tryitonline.net/#code=bGVlX3siYWVpb3UiJn0sX21yZXJXZj0&input=c2hlbmFuaWdhbnM)
### Explanation
```
l            e# Read input, e.g. "foobar".
ee           e# Enumerate, e.g. [[0 'f] [1 'o] [2 'o] [3 'b] [4 'a] [5 'r]].
_            e# Duplicate.
{"aeiou"&},  e# Keep those which have a non-empty intersection with this string
             e# of vowels, i.e. those where the enumerated character is a vowel.
             e# E.g. [[1 'o] [2 'o] [4 'a]].
_            e# Duplicate.
mr           e# Shuffle the copy. E.g. [[2 'o] [4 'a] [1 'o]].
er           e# Transliteration. Replaces elements from the sorted copy with
             e# the corresponding element in the shuffled copy in the original list.
             e# [[0 'f] [2 'o] [4 'a] [3 'b] [1 'o] [5 'r]].
Wf=          e# Get the last element of each pair, e.g. "foabor".
```
[Answer]
# [05AB1E](http://github.com/Adriandmen/05AB1E), 17 bytes
```
žMÃ.r`¹vžMyå_iy}?
```
**Explanation**
```
žMÃ                # get all vowels from input
   .r`             # randomize them and place on stack
      ¹v           # for each in input
        žMyå_i }   # if it is not a vowel
              y    # push it on stack
                ?  # print top of stack
```
[Try it online!](http://05ab1e.tryitonline.net/#code=xb5Nw4MucmDCuXbFvk15w6VfaXl9Pw&input=dGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZy4)
[Answer]
# Python 3, 109 bytes
Only supports lowercase vowels.
Thanks to @Alissa for saving an extra byte.
```
import re,random
def f(s):r='[aeiou]';a=re.findall(r,s);random.shuffle(a);return re.sub(r,lambda m:a.pop(),s)
```
[**Ideone it!**](http://ideone.com/78JIDe)
[Answer]
# TSQL, 275 bytes
**Golfed:**
```
DECLARE @ VARCHAR(99)='the quick brown fox jumps over the lazy dog.'
;WITH c as(SELECT LEFT(@,0)x,0i UNION ALL SELECT LEFT(substring(@,i+1,1),1),i+1FROM c
WHERE i<LEN(@)),d as(SELECT *,rank()over(order by newid())a,row_number()over(order by 1/0)b
FROM c WHERE x IN('a','e','i','o','u'))SELECT @=STUFF(@,d.i,1,e.x)FROM d,d e
WHERE d.a=e.b PRINT @
```
**Ungolfed:**
```
DECLARE @ VARCHAR(max)='the quick brown fox jumps over the lazy dog.'
;WITH c as
(
  SELECT LEFT(@,0)x,0i
  UNION ALL
  SELECT LEFT(substring(@,i+1,1),1),i+1
  FROM c
  WHERE i<LEN(@)
),d as
(
  SELECT 
    *,
    rank()over(order by newid())a,
    row_number()over(order by 1/0)b
  FROM c
  WHERE x IN('a','e','i','o','u')
)
SELECT @=STUFF(@,d.i,1,e.x)FROM d,d e
WHERE d.a=e.b
-- next row will be necessary in order to handle texts longer than 99 bytes
-- not included in the golfed version, also using varchar(max) instead of varchar(99)
OPTION(MAXRECURSION 0) 
PRINT @
```
**[Fiddle](https://data.stackexchange.com/stackoverflow/query/531859/sheffle-tho-vawols-ureund)**
[Answer]
# Perl, 38 bytes
Includes +1 for `-p`
Run with the sentence on STDIN
```
vawols.pl <<< "programming puzzles & code golf"
```
`vawols.pl`:
```
#!/usr/bin/perl -p
@Q=/[aeiou]/g;s//splice@Q,rand@Q,1/eg
```
[Answer]
# Java 7, ~~243~~ 241 bytes
```
import java.util.*;String c(char[]z){List l=new ArrayList();char i,c;for(i=0;i<z.length;i++)if("aeiou".indexOf(c=z[i])>=0){l.add(c);z[i]=0;}Collections.shuffle(l);String r="";for(i=0;i<z.length;i++)r+=z[i]<1?(char)l.remove(0):z[i];return r;}
```
Yes, this can probably be golfed quite a bit, but Java doesn't have any handy built-ins for this a.f.a.i.k... Also, I kinda forgot the codegolfed array-variant for `Collections.shuffle`..
**Ungolfed & test cases:**
[Try it here.](https://ideone.com/DrIglP)
```
import java.util.*;
class M{
  static String c(char[] z){
    List l = new ArrayList();
    char i,
         c;
    for(i = 0; i < z.length; i++){
      if("aeiou".indexOf(c = z[i]) >= 0){
        l.add(c);
        z[i] = 0;
      }
    }
    Collections.shuffle(l);
    String r = "";
    for(i = 0; i < z.length; i++){
      r += z[i] < 1
               ? (char)l.remove(0)
               : z[i];
    }
    return r;
  }
  public static void main(String[] a){
    System.out.println(c("".toCharArray()));
    System.out.println(c("a".toCharArray()));
    System.out.println(c("cwm".toCharArray()));
    System.out.println(c("the quick brown fox jumps over the lazy dog.".toCharArray()));
    System.out.println(c("abcdefghijklmnopqrstuvwxyz".toCharArray()));
    System.out.println(c("programming puzzles & code golf".toCharArray()));
    System.out.println(c("fatalize".toCharArray()));
    System.out.println(c("martin ender".toCharArray()));
  }
}
```
**Possible output:**
```
a
cwm
tha queck brown fox jumps evor tho lezy dig.
ebcdifghujklmnopqrstavwxyz
prigrommeng puzzlos & cade golf
fatelazi
mertan inder
```
[Answer]
# [Perl 6](http://perl6.org/), 65 bytes
```
{my \v=m:g/<[aeiou]>/;my @a=.comb;@a[v».from]=v.pick(*);@a.join}
```
Anonymous function. Assumes lower-case input.
([try it online](https://glot.io/snippets/ei0d9dkfpl))
[Answer]
# Ruby 45 + 1 = 46 bytes
+1 byte for `-p` flag
```
a=$_.scan(e=/[aeiou]/).shuffle
gsub(e){a.pop}
```
[Answer]
# Bash, 75 bytes
```
paste -d '' <(tr aeoiu \\n<<<$1) <(grep -o \[aeiou]<<<$1|shuf)|paste -sd ''
```
Takes the string as an argument and prints the result to stdout.
Eg
```
for x in "" "a" "cwm" \
         "the quick brown fox jumps over the lazy dog." \
         "abcdefghijklmnopqrstuvwxyz" \
         "programming puzzles & code golf" \
         "fatalize" "martin ender"; do
  echo "$x";. sheffle.sh "$x"; echo
done
```
prints
```
<blank line>
<blank line>
a
a
cwm
cwm
the quick brown fox jumps over the lazy dog.
tho quuck brown fix jamps ever the lozy dog.
abcdefghijklmnopqrstuvwxyz
ibcdefghajklmnopqrstuvwxyz
programming puzzles & code golf
progremmong pazzlus & cedo gilf
fatalize
fetilaza
martin ender
mertan endir
```
[Answer]
# [Brachylog](http://github.com/JCumin/Brachylog), 39 bytes
```
@eI:1aToS,I:2f@~:LcS,Tc
.'~e@V;
e.~e@V,
```
[Try it online!](http://brachylog.tryitonline.net/#code=QGVJOjFhVG9TLEk6MmZAfjpMY1MsVGMKLid-ZUBWOwplLn5lQFYs&input=InRoZSBxdWljayBicm93biBmb3gganVtcHMgb3ZlciB0aGUgbGF6eSBkb2cuIg&args=Wg)
### Explanation
* Main predicate:
```
@eI        I is the list of chars of the input.
:1aT       T is I where all vowels are replaced with free variables.
oS,        S is T sorted (all free variables come first).
I:2f       Find all vowels in I.
@~         Shuffle them.
:LcS,      This shuffle concatenated with L (whatever it may be) results in S.
             This will unify the free variables in S with the shuffled vowels.
Tc         Output is the concatenation of elements of T.
```
* Predicate 1:
```
.          Input = Output…
'~e@V      …provided that it is not a vowel.
;          Otherwise Output is a free variable.
```
* Predicate 2:
```
e.         Output is an element of the input…
~e@V,      … and it is a vowel.
```
[Answer]
## Javascript (ES6), ~~78~~ 76 bytes
```
s=>s.replace(r=/[aeiou]/g,_=>l.pop(),l=s.match(r).sort(_=>Math.random()-.5))
```
*Saved 2 bytes thanks to apsillers*
### Alternate version proposed by apsillers (76 bytes as well)
```
s=>s.replace(r=/[aeiou]/g,[].pop.bind(s.match(r).sort(_=>Math.random()-.5)))
```
### Test
```
let f =
s=>s.replace(r=/[aeiou]/g,_=>l.pop(),l=s.match(r).sort(_=>Math.random()-.5))
console.log(f("the quick brown fox jumps over the lazy dog."))
```
[Answer]
# [MATL](http://github.com/lmendo/MATL), 15 bytes
```
tt11Y2m)tnZr7M(
```
[Try it online!](http://matl.tryitonline.net/#code=dHQxMVkybSl0blpyN00o&input=J3RoZSBxdWljayBicm93biBmb3gganVtcHMgb3ZlciB0aGUgbGF6eSBkb2cuJw)
### Explanation
```
tt      % Take input string implicitly. Duplicate twice
11Y2    % Predefined string: 'aeiou'
m       % Logical index that contains true for chars of the input that are vowels
)       % Get those chars from the input string. Gives a substring formed by the
        % vowels in their input order
tnZr    % Random permutation of that substring. This is done via random sampling
        % of that many elements without replacement
7M      % Push logical index of vowel positions again
(       % Assign the shuffled vowels into the input string. Display implicitly
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt) v2.0a0, ~~14~~ 13 bytes
```
ō²f\v
NÌr\v@o
```
[Try it](https://ethproductions.github.io/japt/?v=2.0a0&code=9rJmXHYKTsxyXHZAbw==&input=InRoaXMgaXMgYSB0ZXN0IgotUQ==)
---
## Explanation
```
           :Implicit input of string U.
ö²         :Generate a random permutation of U.
  f\v      :Get all the vowels as an array.
\n         :Assign that array to U.
NÌ         :Get the last element in the array of inputs (i.e., the original value of U)
  r\v      :Replace each vowel.
     @o    :Pop the last element from the array assigned to U above.
```
[Answer]
# Pyth, 26 bytes
```
J"[aeiou]"s.i:QJ3.Sf}TPtJQ
```
A program that takes input of a quoted string and prints the shuffled string.
[Try it online](https://pyth.herokuapp.com/?code=J%22%5Baeiou%5D%22s.i%3AQJ3.Sf%7DTPtJQ&test_suite=1&test_suite_input=%22%22%0A%22a%22%0A%22cwm%22%0A%22the+quick+brown+fox+jumps+over+the+lazy+dog.%22%0A%22abcdefghijklmnopqrstuvwxyz%22%0A%22programming+puzzles+%26+code+golf%22%0A%22fatalize%22%0A%22martin+ender%22&debug=0)
**How it works**
```
J"[aeiou]"s.i:QJ3.Sf}TPtJQ  Program. Input: Q
J"[aeiou]"                  J="[aeiou]"
             :QJ3           Split Q on matches of regex J, removing vowels
                      PtJ   J[1:-1], yielding "aeiou"
                   f}T   Q  Filter Q on presence in above, yielding vowels
                 .S         Randomly shuffle vowels
           .i               Interleave non-vowel and vowel parts
          s                 Concatenate and implicitly print
```
[Answer]
# PHP, ~~144~~ 129 bytes
Using lowercase input
```
$r=Aaeiou;$v=str_shuffle(preg_replace("#[^$r]+#",'',$a=$argv[1]));for(;$i<strlen($a);)echo strpos($r,$a[$i++])?$v[$j++]:$a[$i-1];
```
Explanation:
```
$r="aeiou"; // set vowels
preg_replace("#[^$r]+#",'',$argv[1]) // find all vowels in input
$v=str_shuffle() // shuffle them
for(;$i<strlen($a);) // run through the text
strpos($r,$a[$i++])?$v[$j++]:$a[$i-1]; // if it's a vowel print the j-th shuffled vowel else print original text
```
[Answer]
## Actually, 24 bytes
```
;"aeiou";╗@s@`╜íu`░╚@♀+Σ
```
[Try it online!](http://actually.tryitonline.net/#code=OyJhZWlvdSI74pWXQHNAYOKVnMOtdWDilpHilZpA4pmAK86j&input=Im1lZ28i)
Explanation:
```
;"aeiou";╗@s@`╜íu`░╚@♀+Σ
;                         dupe input
 "aeiou";╗                push vowels, store a copy in reg0
          @s              split one copy of input on vowels
            @`╜íu`░       take characters from other copy of input where
              ╜íu           the character is a vowel (1-based index of character in vowel string is non-zero)
                   ╚      shuffle the vowels
                    @♀+   interleave and concatenate pairs of strings
                       Σ  concatenate the strings
```
[Answer]
# Bash, 89
Assumes all input to be lowercase.
```
a=`tee z|grep -o [aeiou]`
[ -n "$a" ]&&tr `tr -d \ <<<$a` `shuf -e $a|tr -d '
'`<z||cat z
```
[Answer]
## PowerShell v3+, ~~155~~ 99 bytes
```
param([char[]]$n)$a=$n|?{$_-match'[aeiou]'}|sort{random};-join($n|%{if($_-in$a){$a[$i++]}else{$_}})
```
*Big props to @[Ben Owen](https://codegolf.stackexchange.com/users/56849/ben-owen) for the 56-byte golf*
Takes input `$n`, expecting all lowercase, immediately casts it as a `char`-array.
We pipe that into a `Where-Object` clause to pull out those elements that `-match` a vowel, pipe them to `Sort-Object` with `{Get-Random}` as the sorting mechanism. Calling `Get-Random` without qualifiers will return an integer between `0` and `[int32]::MaxValue` -- i.e., assigning random weights to each element on the fly. We store the randomized vowels into `$a`.
Finally, we loop through `$n`. For each element, `|%{...}`, if the current character is somewhere `-in` `$a`, we output the next element in `$a`, post-incrementing `$i` for the next time. Otherwise, we output the current character. That's all encapsulated in parens and `-join`ed together into a string. That string is left on the pipeline, and output is implicit at program conclusion.
### Test cases
```
PS C:\Tools\Scripts\golfing> 'a','cwm','the quick brown fox jumps over the lazy dog.','abcdefghijklmnopqrstuvwxyz','programming puzzles & code golf','fatalize','martin ender'|%{.\vawols.ps1 $_}
a
cwm
thu qaeck brown fix jomps ovor thu lezy deg.
abcdofghejklmnupqrstivwxyz
prugrammong pizzles & code golf
fitaleza
mertin endar
```
[Answer]
# Python 3, 106 bytes
Lowercase only.
```
import re,random
def f(s):s=re.split('([aeiou])',s);v=s[1::2];random.shuffle(v);s[1::2]=v;return''.join(s)
```
[Answer]
# [PHP >= 5.3](http://sandbox.onlinephpfunctions.com/), ~~139~~ 136 bytes (and no errors thrown)
```
array_map(function($a,$b){echo$a.$b;},preg_split("/[aeiou]/",$s=$argv[1]),str_split(str_shuffle(implode(preg_split("/[^aeiou]/",$s)))));
```
[Answer]
# [K (oK)](https://github.com/JohnEarnest/ok), 29 bytes
**Solution:**
```
{x[a:&x in"aeiou"]:x@(-#a)?a}
```
[Try it online!](https://tio.run/##y9bNz/7/v7oiOtFKrUIhM08pMTUzv1Qp1qrCQUNXOVHTPrFWqSQjVaGwNDM5WyGpKL88TyEtv0IhqzS3oFghvyy1SAEknZNYVamQkp@up/T/PwA "K (oK) – Try It Online")
**Examples:**
```
"pregrommeng pizzlas & codo gulf"
{x[a:&x in"aeiou"]:x@(-#a)?a}"programming puzzles & code golf"
"pregremmong puzzlos & coda gilf"
{x[a:&x in"aeiou"]:x@(-#a)?a}"programming puzzles & code golf"
"pregrommeng pazzlos & cidu golf"
```
**Explanation:**
Find locations of the vowels and replace with the vowels drawn in a random order.
```
{x[a:&x in"aeiou"]:x@(-#a)?a} / the solution
{                           } / anonymous function with input x
 x[              ]            / index into x at these indices
      x in"aeiou"             / is character a vowel
     &                        / indices where true
   a:                         / assign to add
                  :           / assign
                          ?a  / draw randomly from a
                     (   )    / do this together
                       #a     / count length of a
                      -       / negate (draws from list, no duplication)
                   x@         / apply these indices to input
```
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 21 [bytes](https://github.com/abrudz/SBCS)
```
{⍵[?⍨≢⍵]}@{⍵∊'AEIOU'}
```
[Try it online!](https://tio.run/##hY/NToNAFIX3PMVdOSWpPoAbpTCltMBQCv3BuKDtUEn4szMsGtOt0SZNjHs3XfkCvhAvUgFLY9y4mu@ec@bkXj@LLpcbP0pXx2L/AWbK6TW4WUbXC59RCJMs5xAy8BnLY7o8PhX7r7ubYv9ZvB5KvN/eVkrxskMS1oiLtse6x/DDBII8WfAwTaDF8nkcMlayKAgBFM9v8G@RIFRFDmX8XCQIvBqr78Xu0EYlvQNqB7@i9dZBuo59/qNq9QVVkOS8xD9ZBq2kvpmyhZ9RYGGyiig85qVYekiE@QaWaT6PSgP4A41LEYniaRWETq/UgDwxGnR6GIauJg@gY5OJCV0yhb5rWCMgY2xDZeuSNwOFqFfnno6s4K7a0/oD3TCJNbRHjjueTGdek7BsotqSYWimCpbreToewQXIRMGgEr3bxLqSI@mah5vZkGxHMwGbCrbRNw "APL (Dyalog Unicode) – Try It Online")
Assumes uppercase.
[Answer]
# [Kotlin](https://kotlinlang.org), ~~122~~ 118 bytes
```
x->val v=x.filter{"aeiuo".contains(it)}.toList().shuffled()
x.split(Regex("[aeiou]")).reduceIndexed{i,a,s->a+v[i-1]+s}
```
[Try it online!](https://tio.run/##bVBNa8MwDL3nV4gchkMbw66F9j7YaTuWHtxYdt36I/VH6ibkt2cu22lEIJDe0@NJurmolV1EsmCYsmRgnnkJJcMOvqNXVjYwVVCiL03UlghS103zH2IrWPcwK2i8INyT6m5w9u5hQbgM12T6AG5ADy9as/EJ3Em6ZnTuOAp5UdebNtb1dx9iGh75Oa4M995Jz4wpZ0CfxlFjgDfoHEeQTosVhWCRaTXiCmWYj8oCWo7@RVdzVQ1Mg9iRv0@1h99iPy25Pby4YZ@pUDqin2qGKrmads7G8upAVGxmGt2nCpE0NFySEBo5aapMQ69VJF8oMZP6WIQunYol9chThx9lg4x8Ulu2De2BbYajat9PmzAv8/ID "Kotlin – Try It Online")
]