[Question]
  [
**The Task**
Your task is to create a program or a function that, given an input, outputs the input text with random letters capitalized, while keeping already capitalized letters capitalized.
Every combination of capitalizations of the lowercase letters should be possible. For example, if the input was `abc`, there should be a non-zero probability of outputting any of the following combinations: `abc`, `Abc`, `aBc`, `abC`, `ABc`, `AbC`, `aBC` or `ABC`.
**Input**
Your input is a string, containing any number of printable ASCII characters, for example `Hello World`. The outputs for that input include `HeLLo WoRlD`, `HElLO WOrld`, etc.
**Scoring**
This is code-golf, so the shortest answer in each language wins!
  
[Answer]
# TI-Basic (83 series), 137 bytes
```
For(I,1,length(Ans
Ans+sub(sub(Ans,I,1)+"ABCDEFGHIJKLMNOPQRSTUVWXYZ",1+int(2rand)inString("abcdefghijklmnopqrstuvwxyz",sub(Ans,I,1)),1
End
sub(Ans,I,I-1
```
Takes input in `Ans`, as illustrated in the screenshot below:
[![enter image description here](https://i.stack.imgur.com/gvOR8.gif)](https://i.stack.imgur.com/gvOR8.gif)
(If the screenshot looks scrambled, as it sometimes does for me, try [opening it in a new tab](https://i.stack.imgur.com/gvOR8.gif)?)
TI-Basic (at least the TI-83 version... maybe I should branch out into TI-89 golfing) is a terrible language to try to golf this challenge in, since:
1. It provides absolutely no support for any arithmetic with characters, knowing the uppercase version of a lowercase character, or even knowing the alphabet.
2. Every single lowercase character takes 2 bytes to store. (In fact, I had to use an [assembly script](http://tibasicdev.wikidot.com/hexcodes#toc5) just to be able to type the lowercase letters.)
The result is that 78 bytes of this program (more than half) are just storing the alphabet, *twice*.
Anyway, the idea is that we loop through the string, with a chance of turning lowercase characters into uppercase ones as we go, and adding the result onto the end of the string so that both the input and the output are stored in `Ans`. When we leave the `For(` loop, `I` is one more than the length of the original string, so taking the `I-1` characters starting at `I` gives the output.
[Answer]
# [Python 2](https://docs.python.org/2/), 66 65 bytes
```
lambda s:`map(choice,zip(s.upper(),s))`[2::5]
from random import*
```
[Try it online!](https://tio.run/##DcWxCoMwEADQ3a8ITndFOghdAt37Bx20YGoSDCS54xIH/fnoWx4fdaM8Nv@eWzTpb40qekmGYd0orG44A0N57sxOAIeCuEyj1q9f54WSEpPtXUhMUh@NJeQKHvqPi5HUlyTaHrFd "Python 2 – Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 6 bytes
```
®m`«`ö
```
[Test it online!](https://ethproductions.github.io/japt/?v=1.4.5&code=rm1gq2D2&input=IkhlbGxvLCBXb3JsZCEi)
### Explanation
```
®m`«`ö   Implicit input
®        Map each char in the input by
 m         mapping each char in this char through
  `«`ö       a random character of "us". (`«` is "us" compressed)
             The u function converts to uppercase, and s is slice, which does nothing here.
         Implicit output
```
[Answer]
# C, ~~47~~ 46 bytes
*Thanks to @l4m2 for saving a byte!*
```
f(char*s){for(;*s++-=(*s-97u<26&rand())*32;);}
```
[Try it online!](https://tio.run/##S9ZNT07@/z9NIzkjsUirWLM6Lb9Iw1qrWFtb11ZDq1jX0rzUxshMrSgxL0VDU1PL2Mha07r2f2ZeiUJuYmaehiZXNZcCEBSDFZRk5qZqGGhqWoPFQCYqFJcURRsbxUJEgJzkgkoNIKWjoOSRmpOTrxCeX5STogTVkQaSgrILSkuKodza/wA)
**Would be 42 bytes, if it could be assumed that `{|}~` don't appear in the input:**
```
f(char*s){for(;*s++-=(*s>96&rand())*32;);}
```
[Try it online!](https://tio.run/##S9ZNT07@/z9NIzkjsUirWLM6Lb9Iw1qrWFtb11ZDq9jO0kytKDEvRUNTU8vYyFrTuvZ/Zl6JQm5iZp6GJlc1lwIQFIMVlGTmpmoYaGpag8VApikUlxRFGxvFQkSAnOSCSg0gpaOg5JGak5OvEJ5flJOiBNWRBpKCsgtKS4qh3Nr/AA)
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 5 bytes
*Another one bytes the dust thanks to dylnan.*
```
żŒuX€
```
[Try it online!](https://tio.run/##y0rNyan8///onqOTSiMeNa35//@/B1AoX6E8vygnBQA "Jelly – Try It Online")
## Explanation
```
żŒuX€  main link: s = "Hello world"
żŒu    zip s with s uppercased  ["HH", "eE", "lL", "lL", "oO", "  ", ...]
   X€  map random choice        "HeLLo woRlD"
```
[Answer]
# [Perl 5](https://www.perl.org/), 23 bytes
**22 bytes code + 1 for `-p`.**
```
s/./rand>.5?uc$&:$&/ge
```
[Try it online!](https://tio.run/##K0gtyjH9/79YX0@/KDEvxU7P1L40WUXNSkVNPz31/3@P1JycfB2F8PyinBTFf/kFJZn5ecX/dQsA "Perl 5 – Try It Online")
[Answer]
# JavaScript (ES6), 56 bytes
```
s=>s.replace(/./g,x=>Math.random()<.5?x.toUpperCase():x)
```
If uniform randomness is not required, we can save 6 bytes by using the current time as the source of randomness:
```
s=>s.replace(/./g,x=>new Date&1?x.toUpperCase():x)
```
This tends to either uppercase or leave alone all letters at once.
[Answer]
# [R](https://www.r-project.org/), 66 bytes
```
for(i in el(strsplit(scan(,""),"")))cat(sample(c(i,toupper(i)),1))
```
[Try it online!](https://tio.run/##FcsxDoAgDEDRqxCmNmHxFt7AGaHGJoWSgoOnRxz@8pJvU/i0aC8UGrfmjvNSA3ZcHQn0Yb0JD@gpVgje4x9iiotiaUKQgMPQpzVaG2LYEKffSUTdoSbZzw8 "R – Try It Online")
Another [R](https://www.r-project.org/) answer.
[Answer]
# Excel VBA, ~~74~~ ~~71~~ 64 Bytes
~~The `Randomize` call always makes random output costly in VBA :(~~ 
Anonymous VBE immediate window function that takes input from range `[A1]` and outputs to the VBE immediate window. Produces a 50% (on average) `UCase`d output.
```
For i=1To[Len(A1)]:a=Mid([A1],i,1):?IIf(Rnd>.5,a,UCase(a));:Next
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), ~~8~~ 7 bytes
```
⭆Ｓ‽⁺↥ιι
```
[Try it online!](https://tio.run/##S85ILErOT8z5/z@gKDOvRCO4BEil@yYWaHjmFZSWQLgamjoKQYl5Kfm5GgE5pcUaoQUFqUXOicWpGplAmUxNILD@/98jNScnX0chPL8oJ0WR679uWQ4A "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
 Ｓ          Input string
      ι     Character
    ↥ι      Uppercase character
   ⁺        Concatenate
  ‽         Random element
⭆           Map over each character and join the result
            Implicitly print
```
[Answer]
# Ruby, 40 Bytes
Lambda function that takes a string. Saved 1 byte thanks to Arnauld. Saved 5 bytes thanks to Snack. 
```
->s{s.gsub(/./){|x|[x,x.upcase].sample}}
```
[Answer]
# APL+WIN, 37 bytes
```
⎕av[c-((n÷2)<n?n←⍴s)×32×s←98<c←⎕av⍳⎕]
```
Prompts for screen input, identifies lower case letters and randomly converts them to upper case.
[Answer]
# [R](https://www.r-project.org/), ~~89~~ 88 bytes
*[outgolfed by djhurio!](http://codegolf.stackexchange.com/a/149518/13849)*
```
cat(sapply(el(strsplit(scan(,""),"")),function(x)"if"(rt(1,1)<0,toupper,`(`)(x)),sep="")
```
[Try it online!](https://tio.run/##FYsxDsIwDAC/gjzZkge6w84PWBtSV0QyieW4En19CMMtdzofWl6e/MSPxLttnUZOgT2Z6Ymi2MO7aZkqp4oMQH@I96PmKK3il6DsgB648EK3K0c7zMR5xZVmJe5i9/kMeIhquzyb6wbjBw "R – Try It Online")
This program takes each character, and with probability 1/2 converts it to uppercase or leaves it alone. It's possible to tweak this probability by playing with different values of `df` and `0`.
`rt` draws from the Student's t-distribution, which has median 0 with any degree of freedom (I selected `1` since it's the smallest number possible).
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), ~~52~~ ~~49~~ 44 bytes
```
StringReplace[c_/;Random[]<.5:>Capitalize@c]
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78H1CUmVcS/T@4BEinB6UW5CQmp0Ynx@tbByXmpeTnRsfa6Jla2TknFmSWJOZkVqU6JMf@d1BQ8kjNycnXUSjPL8pJUVSK/Q8A "Wolfram Language (Mathematica) – Try It Online")
Uses the operator form of `StringReplace`: providing it a rule (or a list of rules) but no string gives a function which applies that rule to any string you give it as input.
We could do a lot better (`RandomChoice@{#,Capitalize@#}&/@#&` is 34 bytes) if we decided to take as input (and produce as output) a list of characters, which people sometimes argue is okay in Mathematica because it's the only kind of string there is in other languages. But that's no fun.
---
*-5 bytes thanks to M. Stern*
[Answer]
# Ruby, 39 bytes
`->s{s.gsub(/./){[$&,$&.upcase].sample}}`
Largely inspired from [displayname's answer](https://codegolf.stackexchange.com/a/149514/76468). (I couldn't comment to suggest this one-byte-less version for lack of reputation, sorry [displayname](https://codegolf.stackexchange.com/users/75921/displayname))
[Answer]
# Swift 4, 86 bytes
```
s.map{let s="\($0)",u=s.uppercased();return u==s ? u:arc4random()%2==0 ? u:s}.joined()
```
[Answer]
# Java 8, 46 bytes
This lambda is from `IntStream` to `IntStream` (streams of code points).
```
s->s.map(c->c>96&c<'{'&Math.random()>0?c-32:c)
```
[Try It Online](https://tio.run/##dU/BSgMxED23XzH20CawG4qCoG1XRBA9FIQePIiHMZt2U7NJSGYra@m3r6ktVESZw7yZx5v3Zo0bzJ1Xdl2@d755M1qCNBgjzFFb2PZ7x2UkpNSW2qKBdVKJhrQRy8ZK0s6K@yOYnrhIQWEtHi0tvlEG/3MFBLSlq017h14TGv2pYNbFvIiiRs9kXsji6nIop6PtaDhHqsRBwHgxvpH5xfm15F1v0v8deON0CXX6hSUjbVcvr4BhFfn@tZ62lGbpSvXkEo4w@yOGQO9NywYPyhgHzy6Y8my729dAyApDZJwLcrchYMv4JJ1dtJFULVxDwidPMpZZ9QGHAOxkl8E4@@EujLIrqvj@xq6/674A)
## Capitalization distribution
Whether to capitalize a letter used to be the quite sensible condition that `Math.random()<.5`, which was satisfied about half the time. With the current condition of `Math.random()>0` (which saves a byte), capitalization occurs virtually every time, which makes a test program kind of pointless. But it does satisfy the randomness requirement.
## Acknowledgments
* -1 byte thanks to Olivier Grégoire
[Answer]
# [Funky](https://github.com/TehFlaminTaco/Funky), 55 bytes
```
s=>s::gsub("."c=>{0s.upper,s.lower}[math.random(2)](c))
```
[Try it online!](https://tio.run/##SyvNy678n2b7v9jWrtjKKr24NElDSU8p2dau2qBYr7SgILVIp1gvJ788tag2OjexJEOvKDEvJT9Xw0gzViNZU/N/QVFmXolGmoaSR2pOTr6OQnh@UU6KohJQBgA "Funky – Try It Online")
Thanks to optional commas, it's one byte shorter to do `0s.upper` in the table definition, which means the `math.random` will randomly pick either `1` or `2`, than to do `math.random(0,1)` in the random and not have the `0`.
[Answer]
# [R](https://www.r-project.org/), ~~60 59 58 57 56~~ 63 bytes
```
intToUtf8((s=utf8ToInt(scan(,"")))-32*rbinom(s,s%in%97:122,.5))
```
[Try it online!](https://tio.run/##K/r/PzOvJCQ/tCTNQkOj2LYUSIfke@aVaBQnJ@Zp6CgpaWpq6hobaRUlZebl52oU6xSrZuapWppbGRoZ6eiZamr@V/JIzcnJVwjPL8pJUQQCpf8A "R – Try It Online")
Different approach from the other two R answers [here](https://codegolf.stackexchange.com/a/149518/80010) and [here](https://codegolf.stackexchange.com/a/149501/80010).
Improved and fixed thanks to Giuseppe!
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~6~~ 5 bytes
*Thank you Adnan for -1 byte*
```
uø€ΩJ
```
[Try it online!](https://tio.run/##MzBNTDJM/f@/9PCOR01rzq30@v@/qqrK0REA "05AB1E – Try It Online")
**Explanation**
```
uø€ΩJ   
u      Upper case of top of stack. Stack: ['ZZZAA']
 ø     Zip(a,b) (uses implicit input). Stack: ['zZ', 'zZ', 'zZ', 'AA', 'AA']
  €    Following operator at each element of its operand
   Ω   Random choice. Stack: ['z', 'Z', 'z', 'A', 'A'] (for example)
    J  Join a by ''. Stack: 'zZzAA'
       Implicit output
```
Method taken from @totallyhuman's answer
[Answer]
# Dyalog APL, ~~23~~ ~~18~~ ~~17~~ 14 bytes
This is a function which takes a string and returns it with random capitalization (as specified in the question).
```
{(?2)⌷⍵,1⎕C⍵}¨
```
**Edits:** Answer improved using suggestions by @LdBeth and @EliasMårtenson at the [APL Orchard](https://chat.stackexchange.com/rooms/52405/the-apl-orchard).
**New Edit:** Answer improved using suggestion by @Adam at APL Orchard.
[Answer]
# [Ouroboros](https://github.com/dloscutoff/Esolangs/tree/master/Ouroboros), 25 bytes
```
i.b*)..96>\123<*?2*>32*-o
```
[Try it here](http://dloscutoff.github.io/Esolangs/)
The only fancy part is the control flow, `.b*)`. Let's talk about the rest first.
```
i..                    Get a character of input, duplicate twice
   96>                 Test if charcode greater than 96
      \                Swap with copy #2
       123<            Test if charcode less than 123
           *           Multiply the two tests (logical AND): test if it is lowercase letter
            ?          Random number between 0 and 1
             2*        Times 2
               >       Is lcase test greater? If test was 1 and rand*2 < 1, then 1, else 0
                32*-   Multiply by 32 and subtract from charcode to ucase lcase letter
                    o  Output as character
```
We then loop back to the beginning of the line. Control flow involves changing where the end of the line is; if it is moved to the left of the IP, execution terminates. Thus:
```
 .     Duplicate input charcode
  b*   Push 11 and multiply
    )  Move end of line that many characters to the right
```
When the charcode is positive, `)` is a no-op, since the end of the line is as far right as it can go. But when all characters have been read, `i` gives `-1`. Then we move the end of the code `-11` characters to the right--that is, 11 characters to the left. It takes a couple iterations, but eventually the IP is past the end of the code and the program halts.
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~12~~ 11 bytes
```
"@rEk?Xk]v!
```
[Try it online!](https://tio.run/##y00syfn/X8mhyDXbPiI7tkzx/391j9ScnHyF8PyinBRFdQA "MATL – Try It Online")
Saved 1 byte thanks to @LuisMendo
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 5 bytes
```
ụᶻṛᵐc
```
[Try it online!](https://tio.run/##ASwA0/9icmFjaHlsb2cy///hu6XhtrvhuZvhtZBj//8iSGVsbG8sIFdvcmxkISL/Wg "Brachylog – Try It Online")
### Explanation
```
Example input: "Test"
ụᶻ        Zip uppercase:      [["T","T"],["e","E"],["s","S"],["t","T"]]
  ṛᵐ      Map random element: ["T","e","S","T"]
    c     Concatenate:        "TeST"
```
[Answer]
## [Alice](https://github.com/m-ender/alice), ~~17~~ 15 bytes
*Thanks to Leo for saving 2 bytes.*
```
/uRUwk
\i*&o.@/
```
[Try it online!](https://tio.run/##S8zJTE79/1@/NCi0PJsrJlNLLV/PQf//f4/UnJx8HYXw/KKcFEUA "Alice – Try It Online")
### Explanation
```
/...
\...@/
```
This is the usual framework for largely linear programs operating entirely in Ordinal mode.
```
i    Read all input as a string.
R    Reverse the input.
&w   Fold w over the characters of the string. w is nullary which means it
     doesn't actually use the individual characters. So what this does is that
     a) it just splits the string into individual characters and b) it invokes
     w once for each character in the string. w itself stores the current 
     IP position on the return address stack to begin the main loop which
     will then run N+1 times where N is the length of the string. The one
     additional iteration at the end doesn't matter because it will just
     output an empty string.
.    Duplicate the current character.
u    Convert it to upper case (does nothing for characters that aren't
     lower case letters).
*    Join the original character to the upper case variant.
U    Choose a character at random (uniformly).
o    Print the character.
k    If the return address stack is not empty yet, pop an address from it
     and jump back to the w.
@    Terminate the program.
```
I first tried doing this entirely in Cardinal mode, but determining if something is a letter just based on character code would probably take more bytes.
[Answer]
# Pyth, ~~10~~ ~~7~~ 6 bytes
```
smO,r1
```
Saved 3 bytes thanks to ovs and 1 thanks to Steven H.
[Try it online](http://pyth.herokuapp.com/?code=smO%2Cr1&input=%22Hello+World%21%22&debug=0)
### Explanation
```
smO,r1
 m      Q   For each character in the (implicit) input...
   ,r1dd    ... get the capitalized version and the (implicit) character, ...
  O         ... and pick one at random.
s           Concatenate the result.
```
[Answer]
# PHP, ~~63~~ 53 bytes
```
while($a=$argv[1][$i++])echo rand()%2?ucfirst($a):$a;
```
Managed to reduce the code with 10 bytes by (partialy) following Titus' suggestion.
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), ~~57~~ 56 bytes
```
-join([char[]]"$args"|%{(("$_"|% *per),$_)[(Random)%2]})
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/XzcrPzNPIzo5I7EoOjZWSSWxKL1YqUa1WkNDSSUeyFDQKkgt0tRRideM1ghKzEvJz9VUNYqt1fz//7@6B9CEfIXw/KKcFHUA "PowerShell – Try It Online")
*-1 byte thanks to briantist*
Takes input as a string, explicitly casts the `$args` array to a string, casts it as a `char`-array, then feeds the characters through a loop. Each iteration, we 50-50 either output the character as-is `$_` or convert it to upper-case `"$_".ToUpper()` (that's the `("$_"|% *per)` garbage). That's chosen by getting a `Random` integer and taking it mod `2`.
Those characters are left on the pipeline and then `-join`ed back together into a single string, which is itself left on the pipeline and output is implicit.
[Answer]
# [Julia](http://julialang.org/), 35 bytes
```
s->map(c->rand([c,uppercase(c)]),s)
```
[Try it online!](https://tio.run/##yyrNyUw0@/9fySM1JydfITy/KCdFUUmhxk6hWNcuN7FAI1nXrigxL0UjOlmntKAgtSg5sThVI1kzVlOnWBOkrKAoM6/k/38A "Julia 0.6 – Try It Online")
Still pretty easy to read as a human.
In Julia rand(A) returns a random element from A.
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 28 bytes
28 bytes (<https://github.com/abrudz/SBCS/>)  
50 bytes (UTF-8)
```
{1(819⌶)@(?n⍴⍨?n←≢⍸~⍵∊⎕A)⊢⍵}
```
Inspired by [Graham](https://codegolf.stackexchange.com/users/6949/graham)'s [APL+Win solution](https://codegolf.stackexchange.com/a/149505/84204)
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///v9pQw8LQ8lHPNk0HDfu8R71bHvWuANJtEx51LnrUu6PuUe/WRx1dj/qmOmo@6gKKbK39/x8A "APL (Dyalog Unicode) – Try It Online")
]