[Question]
  [
Numbers that are easy to remember yet theoretically not easily made
Your challenge is to make a program/function in any language that generates uniformly random numbers that fit these criteria:
1. **Length** is **5 digits**
2. There are two separate repeated digit pairs
3. One set of repeated digits is at the beginning or end and the digits
are next to each other
4. The odd number out is surrounded by the other pair of digits
5. **The two digit pairs and the other number should all be unique**
6. Your program may support numbers with leading zeroes or not, at your discretion. If leading zeroes are supported, they must be included in the output: 06088, not 6088. If leading zeroes are not supported, then numbers like 06088 should not be generated at all.
# Test Cases
## Accepted Outputs:
```
55373
55494
67611
61633
09033
99757
95944
22808
65622
22161
```
## Not accepted outputs:
```
55555
77787
85855
12345
99233
12131
abcde
5033
```
More acceptable test cases can be found at [this pastebin link](https://pastebin.com/iMgVUTCE).
These were made with this python program:
```
import random
for i in range(100):
    
    if random.randint(0,100) >= 50: #Put pair touching at beginning if true
        temp = []                      #working array
        temp.append(random.randint(0,9))  #append random digit
        temp.append(temp[0])              #append the same digit again
        
        x = random.randint(0,9)
        while x == temp[0]:
            x = random.randint(0,9)
        temp.append(x)                    #append another unique digit
        y = random.randint(0,9)
        while y == temp[0] or y == temp[2]:
            y = random.randint(0,9)
        temp.append(y)                  #append another unique digit, and the previous unique digit
        temp.append(x)
    else:  #Put touching pair at end
        temp = []                      #working array  
        temp.append(random.randint(0,9))  #append random digit
        
        #While not unique, try again
        x = random.randint(0,9)
        while x == temp[0]:
            x = random.randint(0,9)
        temp.append(x)                    #append another unique digit
        temp.append(temp[0])              #append the same 0th digit again
        
        y = random.randint(0,9)
        while y == temp[0] or y == temp[1]:
            y = random.randint(0,9)
        temp.append(y)                  #append another unique digit twice
        temp.append(y)
    tempstr = ""
    for i in temp:
        tempstr += str(i)
    print tempstr
```
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest answer in bytes wins!
  
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 11 bytes
```
žh.r3£ûÁÂ)Ω
```
[Try it online!](https://tio.run/##MzBNTDJM/f//6L4MvSLjQ4sP7z7ceLhJ89zK//8B "05AB1E – Try It Online")
**Explanation**
```
žh            # push "0123456789"
  .r          # random shuffle
    3£        # take the first 3
              # EX: 152
      û       # palendromize
              # EX: 15251
       Á      # rotate right
              # EX: 11525
        Â)    # pair with its reverse
              # EX: [11525, 52511]
          Ω   # pick one at random
```
[Answer]
## CJam (16 bytes)
```
YmrG*98+ZbA,mrf=
```
[Online demo](http://cjam.aditsu.net/#code=YmrG*98%2BZbA%2Cmrf%3D)
Note: I've assumed that by "unique" OP really means "distinct".
Also for 16 bytes:
```
98ZbA,mrf=W2mr#%
98ZbA,mrf=_W%]mR
```
### Dissection
```
Ymr    e# Select a random number from [0 1]
G*98+  e# Multiply by 16 and add 98 to get 98 or 114
Zb     e# Base conversion in base 3 to get [1 0 1 2 2] or [1 1 0 2 0]
A,mr   e# Shuffle the numbers from 0 to 9
f=     e# Map "select the item at this index"
```
The other variants generate using `[1 0 1 2 2]` and then select either the result or its reverse.
[Answer]
# [Perl 5](https://www.perl.org/), ~~81~~ ~~63~~ 56 bytes
*Cut 7 bytes with inspiration from @DomHastings*
Constructing the number from the appropriate pattern.
```
@q{0..9}++;say+(keys%q)[.5>rand?(2,2,0,1,0):(0,1,0,2,2)]
```
[Try it online!](https://tio.run/##K0gtyjH9/9@hsNpAT8@yVlvbujixUlsjO7WyWLVQM1rP1K4oMS/FXsNIx0jHQMdQx0DTSgNMA/lGmrH//yv8yy8oyczPK/6v62uqZ2BoAAA "Perl 5 – Try It Online")
---
## [Perl 5](https://www.perl.org/), 89 bytes
Picks random 5 digit numbers until it finds one that meets the criteria.
```
$_=sprintf'%05d',0|rand 1E5until(/(.)\1(.)(.)\2/||/(.)(.)\1(.)\3/)&&$1-$2&$2-$3&$1-$3;say
```
[Try it online!](https://tio.run/##K0gtyjH9/18l3ra4oCgzryRNXdXANEVdx6CmKDEvRcHQ1bQ0ryQzR0NfQ08zxhBIgGgj/ZoafSgbJBZjrK@ppqZiqKtipKZipKtiDGYbWxcnVv7//y@/oCQzP6/4v66vqZ6BoQEA "Perl 5 – Try It Online")
[Answer]
# [Python 2](https://docs.python.org/2/), 80 bytes
```
from random import*
a,b,c=sample(range(10),3)
print[a,a,b,c,b][::choice((-1,1))]
```
[Try it online!](https://tio.run/##K6gsycjPM/r/P60oP1ehKDEvBUhl5hbkF5VocSXqJOkk2xYn5hbkpGoA5dJTNQwNNHWMNbkKijLzSqITdcAqdJJio62skjPyM5NTNTR0DXUMNTVj//8HAA "Python 2 – Try It Online")
Outputs a list of digits.
# [Python 2](https://docs.python.org/2/), 83 bytes
```
from random import*
a,b,c=sample('0123456789',3)
print(a*2+b+c+b)[::choice((-1,1))]
```
[Try it online!](https://tio.run/##DcVLCoAgFADAfadol@YLUvsKnSRaqBUJ@cHcdHprNhPedHnHcj6jt2WUbv8zNviY6kKCAr080ob7QFVLGe/6YZzmCjguQjQuIVkzoogmCq9C6MsbfSDUUKAYbzl/ "Python 2 – Try It Online")
Output is a number.
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), ~~22 21 20 18~~ 17 bytes
```
(3∨?2)⌽1↓,∘⌽⍨3?10
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///qG9qZv6jtgkG/9OBpIbxo44V9kaaj3r2Gj5qm6zzqGMGkPmod4WxvaHB///pAA "APL (Dyalog Unicode) – Try It Online")
If it's acceptable to output the numbers always in the same format, this can be shortened to 12 bytes, either `1⌽1↓,∘⌽⍨3?10` or `3⌽1↓,∘⌽⍨3?10`.
Saved a byte by removing the unnecessary `∘`.
Saved a byte thanks to H.PWiz, and then 2 more bytes due to their tip.
Saved a byte thanks to ngn.
The function assumes `⎕IO←0` (**I**ndex **O**rigin).
---
### How?
```
(3∨?2)⌽1↓,∘⌽⍨3?10 ⍝ Anonymous function.
              3?10  ⍝ Deal 3 (distinct) random numbers from 0 to 9. (Assume 1 2 3)
             ⍨     ⍝ Use that as both arguments for:
          ,∘⌽      ⍝ Rotate (⌽), then concatenate (,).
                   ⍝ Yields 3 2 1 1 2 3.
        1↓         ⍝ Drop the first element. Our vector is now 2 1 1 2 3
      ⌽            ⍝ Rotate the vector to the left using as argument:
(  ?2)             ⍝ Roll 0 or 1 and...
 3∨                ⍝ Do the GCD between 3 and the result. (3∨0=3; 3∨1=1.)
                   ⍝ This yields either 1 1 2 3 2 or 2 3 2 1 1.
```
[Answer]
# Java 8, ~~145~~ ~~136~~ ~~125~~ 119 bytes
```
v->{String r;for(;!(r=(int)(Math.random()*1e5)+"").matches("((.).?\\2){2}")|r.chars().distinct().count()<3;);return r;}
```
-9 bytes thanks to *@OlivierGrégoire.*  
-11 bytes thanks to *@RickHitchcock*.  
-6 bytes thanks to *@Nevay*.
**Explanation:**
[Try it online.](https://tio.run/##fVJNc5swFLz3V7zq0JHqsWKExYep3Vt7Si7N9NL0oMhKIAHhkYSnGde/3ZUxZMYauwwM0r7Vsvt4L2Irpu1G6Zf160HWwlq4FZXefQCotFPmSUgFd8ctwA9nKv0MEv9sqzVsSeHRvX/8bZ1wlYQ70LCEw3a62g1kUzy1BhcfsVliL0jwrXAlNUKv2waTz5HiZIIQoY1wslQWI4wpoV8fHhjZsT0ifw2VpTAWE7qurKu0dH4p207795e4IIVRrjPaf2h/KE5mNt1j7c0MnrZHs43PhE@Wfv0WZMjzZp1qaNs5uvEVV2uMviutjHAKGIeTS9Bd86iMXaA@MMAxkGdDtWS8qKbT1awgfeGioqYS666uyXD6AsVXrvq5V9aBKxUY9az@gHcEYx/g2Bgh/U/yKyVf3w3e3MC96Vz5tui3zktgxHmcxiNjhOb5/BxK0iSKAihK4uDgLJ@FUJ6nPA0gns8DecayWRbI84SxkBUl7yYu92uI@U3UVgUx/XUul6ZpFljLeBayIhbPeZiJjTHPx7wfqZ4zTvn1iTITtAA0webqiH/634ivljEZHOwP/wA)
```
v->{            // Method with empty unused parameter and String return-type
  String r;     //  Result-String
  for(;!(r=(int)(Math.random()*1e5)+"")
                //  Generate a random number in the range [0; 100000) and set it to `r`
        .matches("(.).*\\1(.).*\\2")
                //   And continue doing this as long as it doesn't match the regex above,
       |r.chars().distinct().count()<3;);
                //   or doesn't have three distinct digits
  return r;}    //  Return the result
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 23 bytes
```
⁵Ḷṗ3⁼Q$ÐfXµḢ;`;ŒBW;U$µX
```
[Try it online!](https://tio.run/##y0rNyan8//9R49aHO7Y93Dnd@FHjnkCVwxPSIg4BRRZZJ1gfneQUbh2qcmhrxP//AA "Jelly – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~12~~ 11 bytes
```
ØDẊ⁽0yṃ,U$X
```
[Try it online!](https://tio.run/##AS8A0P9qZWxsef//w5hE4bqK4oG9MHnhuYMsVSRY/@KAnOKAnSDCouG5rSQgMzDCoSBZ/w "Jelly – Try It Online")
---
# Explanation
```
ØDẊ⁽0yṃ,U$X    Niladic link, generate a random string.
ØD             List of digits, ['0','1','2',...,'9'].
  Ẋ            Random shuffle.
   ⁽0y         Number 13122.
      ṃ        Base decompression. (\*)
       ,U$     Pair with its upend (reverse).
          X    Choose one (it or its reversed) randomly.
```
(\*) The right argument of `ṃ` is the list `['0','1','2',...,'9']`, randomly shuffled, have 10 elements. So the number `13122` will be converted to bijective base 10 (`[1,3,1,2,2]`) and index into the list (so if the list is `l`, the return value of the atom is `[l[1],l[3],l[1],l[2],l[2]]`, where Jelly uses 1-based indexing)
[Answer]
# JavaScript (ES6), 79 bytes
```
f=([,,d,a,b,c]=[...Math.random()+f])=>a-b&&a-c&&b-c?d&1?a+a+b+c+b:b+c+b+a+a:f()
```
[Try it online!](https://tio.run/##HYpLDsIgFAD3PcVbEcgDogs3rdgTeIKmiwcUP0EwlLgxnh2rm5lMMnd60erK7VlVyn5pLRg@SeklSSvdbCat9ZnqVRdKPj@4wDALcyJlGSPlGLPKjZ7tR0JCiw5t/@dW1AcuWsiFx6VCAgO7YdMRDj8jCnh3AC6nNcdFx3zh2y@G7tO@ "JavaScript (Node.js) – Try It Online")
### How?
`Math.random()` gives a random float in **[0..1)**. We use `+f` to force coercion to a string. We ignore the leading zero and the decimal point by doing `[,,` ([destructuring assignment](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment) of the first two characters to nothing) and collect the first 4 decimal digits into **d**, **a**, **b**, and **c**.
If **a**, **b** and **c** are 3 distinct integers, we build the final output in either **AABCB** or **BCBAA** format (using the parity of **d** to decide). Otherwise, we try again until they are.
In the highly improbable event of `Math.random()` returning a value without enough decimal places, at least **c** will be set to a non-digit character, forcing the test to fail and the recursive call to occur. If **a**, **b** and **c** are valid integers then **d** is guaranteed to be a valid integer as well, so this one doesn't need to be tested.
[Answer]
# [Perl 6](http://perl6.org/), 42 bytes
```
[~] (^10).pick(3)[0,|(<0 2 1>,<1 0 2>).pick,2]
```
[Try it online!](https://tio.run/##K0gtyjH7X5xYqfE/ui5WQSPO0EBTryAzOVvDWDPaQKdGw8ZAwUjB0E7HxlAByLKDSOoYxf7XVKioUDA0@A8A "Perl 6 – Try It Online")
[Answer]
# [Dirty](https://github.com/Ourous/dirty), 33 bytes
Uses the `--numeric-output` flag so it's readable, otherwise it would output a string of control characters with code-points corresponding to the digits.
```
10⭧[1w#%D⅋№3⤱≠1ẅ&]1wẂ⭿⭣1u∅#1∧◌ŪW‼
```
[Try it online!](https://tio.run/##AV4Aof9kaXJ0ef//MTDiradbMXcjJUTihYvihJYz4qSx4omgMeG6hSZdMXfhuoLirb/iraMxdeKIhSMx4oin4peMxapX4oC8///@b3B0aW9uc/8tLW51bWVyaWMtb3V0cHV0 "Dirty – Try It Online")
**Explained:**
```
10⭧              put 10 on the right stack
[1w#%D⅋№3⤱≠1ẅ&] loop until there are 3 distinct positive numbers below 10 in the top stack
1wẂ              clean-up the right and top stacks
⭿               copy the top and bottom of the top stack to each-other
⭣                swap the first two elements of the top stack
1u               rotate the top stack by 1
∅#1∧◌ŪW          reverse the top stack half of the time
‼                print the top stack
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 34 bytes
```
≔‽χθ≔‽Φχ⁻ιθη↑Ｉ⟦θθη‽Φχ×⁻ιθ⁻ιηη⟧¿‽²‖
```
[Try it online!](https://tio.run/##ZY0xCwIxDEZ3f0XGBCqoozeJ4CbIoZM4lNqzgV7Pa6t/P0ZEOHHNe9@LCza7wUaRTSl8S9jadB16XC7IwEjN7Pe841h9Vmpgz@lRkN8WqRvUPWROFdenu4GtLRXPo1JFBv7nR@59wUlkUgz0SV5Io9zB9/uKCFrfRe8qUiMi82d8AQ "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
  χ                                 Predefined variable 10
 ‽                                  Random element from implicit range
≔  θ                                Assign to variable `q`
       χ                            Predefined variable 10
      Φ                             Filter on implicit range
         ι                          Current value
          θ                         Variable `q`
        ⁻                           Subtract
     ‽                              Random element
    ≔      η                        Assign to variable `h`
                    χ               Predefined variable 10
                   Φ                Filter on implicit range
                       ι  ι         Current value
                        θ           Variable `q`
                           η        Variable `h`
                      ⁻  ⁻          Subtract
                     ×              Multiply
                  ‽                 Random element
               θθ                   Variable `q`
                 η          η       Variable `h`
              ⟦              ⟧      Wrap 5 values into array
             Ｉ                      Cast array elements to string
            ↑                       Make array print horizontally
                                ²   Literal 2
                               ‽    Random element from implicit range
                              ¿     If
                                 ‖  Reflect
```
[Answer]
## [Retina](https://github.com/m-ender/retina/wiki/The-Language), 40 bytes
```
10*
Y`w`d
V?`
Lv$7`.(.)
$1$<'$'
O?`...?
```
[Try it online!](https://tio.run/##K0otycxLNPz/n8vQQIsrMqE8IYUrzD6By6dMxTxBT0NPk0vFUMVGXUWdy98@QU9Pz/7/fwA "Retina – Try It Online")
Can print strings with leading zeros.
### Explanation
```
10*
```
Initialise the string to 10 underscores.
```
Y`w`d
```
Cyclically transliterate word characters to digits. This is a bit weird. The `w` and `d` are short for the following strings, respectively:
```
w: _0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
d: 0123456789
```
Cyclic transliteration means that first, both strings are repeated to the length of the their LCM:
```
_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_012345...
0123456789012345678901234567890123456789012345678901234567890123456789...
```
Since the string lengths 53 and 10 are coprime, each copy of `_` is paired with a different digit. And now cyclic transliteration will replace the **i**th copy of `_` with the **i**th pairing in that expanded list. So we end up with the following string:
```
0369258147
```
All of that to save a single byte over the literal string `0369258147`, so yay I guess? :D
Anyway, we've got a string of all 10 digits now.
```
V?`
```
This shuffles the digits. So the first three digits will be a uniformly random selection of three distinct digits.
```
Lv$7`.(.)
$1$<'$'
```
We match the string `...ABC` and turn it into `BABCC`. The way we do this is kinda crazy though and again saves only one byte compared to a more straightforward approach. We first match all *overlapping* (`v`) pairs of characters, capturing the second one (`.(.)`). Then we retain only the 8th match (`7`, zero-based) which is `AB` in `...ABC`. Then we replace (`$`) it with: `B` (`$1`), `ABC` (`$<'` which is the suffix of the match-*separator* left of the match), `C` (`$'` which is the suffix of the match itself).
```
O?`...?
```
Finally, we match either 3 or 2 characters and shuffle the matches, giving us either `BABCC` or `CCBAB` at random.
[Answer]
# [R](https://www.r-project.org/), 78 bytes
```
z=sample(0:9,3)[c(2,1:3,3)];cat(paste(`if`(runif(1)>.5,z,rev(z)),collapse=''))
```
[Try it online!](https://tio.run/##DcZBCoAgEADA57gLS2TSIcM@EoEiCoKVqHXw89acJvfeVDFnig5GuZDA3cJEXIq/x2pNhWRKdaCD15CfK3jguA0zNcruhYZI9o7RpOIUY4i9fw "R – Try It Online")
`sample` picks 3 random values from `0:9`, which are placed in a vector like so: `a b a c c`. Now we have a 50/50 chance to reverse this vector, and then concatenate and print.
[Answer]
# [Ruby](https://www.ruby-lang.org/en/), 60 59 bytes
```
->{a,b,c=[*0..9].sample 3;[[a,a,b,c,b],[b,c,b,a,a]].sample}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1646USdJJ9k2WstAT88yVq84MbcgJ1XB2Do6OlEHLKWTFKsTDaaB/MRYmJLa/4ameiWZuanFCin5XAoKBaUlxQpp0bF6WfmZeVypeSn/AQ "Ruby – Try It Online")
It returns a list of digits.
[Answer]
# PHP, ~~73~~ ~~72~~ 66 bytes
```
<?=strtr(rand()%2?AABCB:BCBAA,ABC,join(array_rand(range(0,9),3)));
```
**Edit:** 66 bytes thanks to @David 's suggestion.
[Try it online!](https://tio.run/##K8go@P/fxt62uKSopEijKDEvRUNT1cje0dHJ2ckKiB0ddYBMnaz8zDyNxKKixMp4sBogkZ6qYaBjqaljrKmpaf3//7/8gpLM/Lzi/7p5AA)
[Answer]
# [Red](http://www.red-lang.org), 147, 146 125 bytes
```
func[][b: copy[]d:[1 1 2 3 2]if 1 = random 2[d: reverse d]while[4 > length? b][alter b(random 10)- 1]foreach a d[prin b/(a)]]
```
[Try it online!](https://tio.run/##LYtBDoIwFAX3nuItYWGg1RWJege3P3/R0l8hgZaUKvH0lRh2M5NMElee4kCMZIKLc7PKriFuTR5nOfmu@Hfoicl26OPyJXYdKShoXKB59DvejheaXIckH0mrwPE2jJPQFXdMEl55eMAymSlLgq2ORbX1GYp9TGL6AQaOljQG2KYyNXOZYlyg23/M8Fx@ "Red – Try It Online")
## Ungolfed:
```
f: func[] [                       function with no arguments
    b: copy []                    an empty list
    d: [1 1 2 3 2]                preset digits at positons
    if 1 = random 2 [             generate 1 or 2 
        d: reverse d]             based on this choose to reverse the positions list
    while [4 > length? b] [       while we haven't chosen 3 different digits
        alter b (random 10) - 1   pick a random digit, if it's not in the list already
                                  append it to the list, otherwise remove it
    ]
    foreach a d [                 for each position
       prin b/(a)]                print the corresponding digit 
]
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 59 bytes
```
{{#,##,#2},{#2,##,#3}}~r~1&@@(r=RandomSample)[0~Range~9,3]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n6Zgq/C/ulpZRxmIjGp1qpWNwEzj2tq6ojpDNQcHjSLboMS8lPzc4MTcgpxUzWiDOiA/PbXOUsc4Vu1/QFFmXkl0WnRs7H8A "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# Python 3 +numpy, 69 bytes
```
from pylab import*
r=choice
i=r(2)
print(r(10,3,0)[[1-i,0,1,2,-1-i]])
```
Explanation
```
from pylab import*     
r=choice               # `choice` takes a range, number of samples, and wether repetition is allowed
i=r(2)                 # Single value in [0,1] to specify if repeated digits come on right or left
print(r(10,3,0)[[1-i,0,1,2,-1-i]])    # Construct output using index list and 3 random integers
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 126 119 bytes
-6 bytes from @ceilingcat
```
#define R time(0)%10
b,n,m,k;f(){b=R^8;for(n=R;m==n|k==m|k==n;m=R,k=R);printf("%d%d%d%d%d",b?n:m,b?n:k,m,b?k:n,b?m:n);}
```
[Try it online!](https://tio.run/##NY1BCsIwEEX3nqJUCgmMUHeSMPQOOUDBpImEYUYp3WnPHqeCfHift/k/XR4ptXZecqmSu9BtlbMZ7XAdTxEEGMgXY98Rw3zz5bkaweAZUT6EyAdENQBhsP61VtmK6Yflnx7iJI5/JDianCjZifV743sVXdcHlS8 "C (gcc) – Try It Online")
[Answer]
# [J](http://jsoftware.com/), 35 bytes
```
[:u:48+[:|.^:(?&2:)2 2 1 0 1{3?10"_
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/o61KrUwstKOtavTirDTs1YysNI0UjBQMgUoMq43tDQ2U4v9rcilwpSZn5CukKRkoZOoZG/wHAA "J – Try It Online")
I'm sure it can be golfed much further.
## Explanation:
```
  3?10             - generates 3 different digits
7 0 3
  2 2 1 0 1{       - constructs a list using digits positions 0, 1 and 2
  2 2 1 0 1{3?10   
3 3 0 7 0
  |.^:(?&2:)       - generates 0 or 1 and if 1, reverses the list 
  |.^:(?&2:)2 2 1 0 1{3?10
0 7 0 3 3
   u:48+              - converts to char by adding 48 to each digit
   u:48+|.^:(?&2:)2 2 1 0 1{3?10
07033
```
]