[Question]
  [
# Challenge
I'm under attack by the larcenous Midnight Crew and I need to summon the [Catenative Doomsday Dice Cascader](https://www.homestuck.com/extras/20) in order to defend myself. Since I'm low on space, I need the code to be as short as possible.
The algorithm for the Catenative Doomsday Dice Cascader is as follows:
First, the six sided die in the Prime Bubble is rolled, and the result will determine how many iterations of the next step take place.
Start with a six sided die. For as many times as the roll of the Prime Bubble die, multiply the number of sides on the next die by the result of the roll of the current die.
For example, if on your first roll of the six-sided die your roll is 2, then your next die will have 6\*2 = 12 sides.
Your goal is to write a function or program that takes no input and outputs the final result of the last die rolled. Since this is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), the lowest byte count in each language wins!
# Examples
Example #1 (Taken directly from the link above):
```
The Prime Bubble rolls a 6, meaning that the Cascader will iterate six times
#1: We always start with a 6 sided die, and it rolls a 2, so the next die has 6x2=12 sides
#2: The 12 sided die rolls an 8, meaning that the third die has 12x8=96 sides
#3: The 96 sided die rolls a 35, meaning that die 4 has 96x35=3360 sides
#4: The 3360 sided die rolls a 2922, so die 5 has 3360x2922 = 9,817,920 sides
#5: The 9.8 million sided die rolls a 5,101,894, so the final die has 50,089,987,140,480 sides
#6: The 50 trillion sided die rolls a one. Hooray. 
Since the last die rolled gave a 1, your function or program should output 1.
```
Example #2
```
The Prime Bubble rolls a 2, meaning that the Cascader will iterate twice.
#1: We always start with a 6 sided die, and it rolls a 4, so the next die has 6x4 = 24 sides
#2: The 24 sided die rolls a 14
Since the last die rolled gave a 14, your function or program should output 14.
```
  
[Answer]
# [Python 2](https://docs.python.org/2/), ~~76~~ 69 bytes
```
from random import*
R=randint
v=6;exec"p=R(1,v);v*=p;"*R(1,6)
print p
```
[Try it online!](https://tio.run/##FY2xDsIwDERn/BVWlzQRC0h0IPJP9A9Qm0KGxpYVRfD1IZ5Od7p7J7/64XLvG@@J1DnXD@UT9VX2IfkU1hpgJQtyqdBoiembtklonW/X5mMLJHEK5hYPoqOF0gcJ4GDFjLkY7p3mh3/CxcZob/0P "Python 2 – Try It Online")
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), ~~43~~ 37 bytes
*-6 bytes thanks to nwellnhof*
```
{(6,{roll 1..[*] @_:}...*)[1+6.rand]}
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYKvwv1rDTKe6KD8nR8FQTy9aK1bBId6qVk9PT0sz2lDbTK8oMS8ltvZ/cWKlQpqG5n8A "Perl 6 – Try It Online")
Anonymous code block that returns the doomsday dice result.
### Explanation:
```
{                                   }   # Anonymous code block
 (                       )[1+6.rand]    # Take a random number from
                     ...*               # The infinite list of
  6,{roll 1..[*] @_:}                   # Cascading dice values
  6,                                    # Starting from 6
    {roll          :}                   # And choosing a random value from
          1..                           # One to
             [*] @_                     # The product of every value so far
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 43 bytes
```
(r=RandomInteger)@{1,Nest[r@{1,#}#&,6,r@5]}
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2Zl@1@jyDYoMS8lP9czryQ1PbVI06HaUMcvtbgkugjEUq5VVtMx0ylyMI2t/V@iYKuQVheSmJSTWmdoYMAVUJSZV6LvUPIfAA "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# [J](http://jsoftware.com/), 21 bytes
```
1+[:?(*1+?)^:(?`])@6x
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/DbWjrew1tAy17TXjrDTsE2I1Hcwq/mtycRWlFpZmFqUqqOeV5qYWZSarcxUl5qXk52ZWpaqrc3GlJmfkK@joKWikKRloKhgbKKgoGPwHAA "J – Try It Online")
*+6 bytes thanks to a logic problem spotted by FrownyFrog*
NOTE: J has no niladic verbs. However, this verb will work the same no matter what argument you give it. In the TIO example, I'm calling it with `0`, but I could have used `99` or `''` just as well.
## how
* `1+` add one to...
* `[:?` a single roll of an n-sided die (sides reading `0` to `n-1`), where the number `n` is determined by...
* `(*1+?)` take the current argument `y` and roll `?` to produce a random number between `0` and `y-1`. `1+` makes that `1` to `y`, inclusive. Finally the `*` creates a J hook, which will multiply that by `y` again.
* `^:` do the above this many times...
* `(?`])` `?` roll the initial argument, which is `6`, to determine how many times to repeat. If we roll `0` (corresponding to a `1` on the Prime Bubble), the argument will pass through unchanged. The `]` indicates that `6`, unchanged, will be the starting value of repeated `(*1+?)` verb that determines the die value for the final roll.
* `@6x` attaches the constant verb `6`, so that we can call it with anything, and the `x` forces J to use extended integer computation which we need for the possibly huge numbers.
[Answer]
# [K (oK)](https://github.com/JohnEarnest/ok), 32 bytes
**Solution:**
```
*|{x,1+1?x:(*).x}/[*a;6,a:1+1?6]
```
[Try it online!](https://tio.run/##y9bNz/7/X6umukLHUNvQvsJKQ0tTr6JWP1or0dpMJ9EKJGgW@/8/AA "K (oK) – Try It Online")
Start with 6 and "1 choose 6", iterate over "1 choose 6" times:
```
*|{x,1+1?x:(*).x}/[*a;6,a:1+1?6] / the solution
  {             }/[n;    c     ] / iterate over lambda n times with starting condition c
                            1?6  / 1 choose 6, between 0..5 (returns a list of 1 item)
                          1+     / add 1 (so between 1..6)
                        a:       / store as 'a'
                      6,         / prepend 6, the number of sides of the first dice
                   *a            / we are iterating between 0 and 5 times, take first (*)
           (*).x                 / multi-argument apply (.) multiply (*) to x, e.g. 6*2 => 12
         x:                      / save that as 'x'
       1?                        / 1 choose x, between 0..x-1
     1+                          / add 1 (so between 1..x)
   x,                            / prepend x
*|                               / reverse-first aka 'last'
```
You can see the iterations by switching the [over for a scan](https://tio.run/##y9bNz/7/n6u6QsdQ29C@wkpDS1OvojYmWivR2kwn0QokaBbL9f8/AA "K (oK) – Try It Online"), e.g.
```
(6 3        / 1 choose 6 => 3, so perform 3 iterations
 18 15      / 1 choose (6*3=18) => 15
 270 31     / 1 choose (18*15=270) => 31
 8370 5280) / 1 choose (270*31=8730) => 5280
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 9 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
6X×$5Ð¡XX
```
A niladic Link which yields a positive integer.
**[Try it online!](https://tio.run/##y0rNyan8/98s4vB0FdPDEw4tjIj4/x8A "Jelly – Try It Online")**
Saving a byte over the more obvious `6X×$6X’¤¡X`
### How?
```
6X×$5Ð¡XX - Link: no arguments
6         - initialise left argument to 6
    5Ð¡   - repeat five times, collecting up as we go: -> a list of 6 possible dice sizes
   $      -   last two links as a monad = f(v):           e.g [6,18,288,4032,1382976,216315425088]
 X        -     random number in [1,v]                     or [6,6,6,6,6,6]
  ×       -     multiply (by v)                            or [6,36,1296,1679616,2821109907456,7958661109946400884391936]
       X  - random choice (since the input is now a list) -> faces (on final die)
        X - random number in [1,faces]
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 10 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
X6DLΩF*DLΩ
```
The random choice builtin for large lists is pretty slow, so may result in a timeout if the Prime Bubble roll is for example a 6.
[Try it online](https://tio.run/##MzBNTDJM/f8/wszF59xKNy0Q@f8/AA) or [try it online with added prints to see the rolls](https://tio.run/##MzBNTDJM/f8/wszF59xKpYCizNxUBafSpKScVIWi/JwcKwUle1s3LRelICBHITNPoSgxLz1VIdpQ5/D@WJAkSJvt//8A). (TIO uses the legacy version of 05AB1E, since it's slightly faster.)
**Explanation:**
```
X           # Push a 1 to the stack
 6          # Push a 6 to the stack
  D         # Push another 6 to the stack
   L        # Pop the top 6, and push a list [1,2,3,4,5,6] to the stack
    Ω       # Pop and push a random item from this list (this is out Prime Bubble roll)
     F      # Loop that many times:
      *     #  Multiply the top two values on the stack
            #  (which is why we had the initial 1 and duplicated 6 before the loop)
       D    #  Duplicate this result
        LΩ  #  Pop and push a random value from its ranged list again
            # (after the loop, output the top of the stack implicitly)
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 9 bytes
```
6×X$X’$¡X
```
[Try it online!](https://tio.run/##y0rNyan8/9/s8PQIlYhHDTNVDi2M@P8fAA "Jelly – Try It Online")
[Jonathan Allan's answer](https://codegolf.stackexchange.com/a/186306/41024) claims that it's
> 
> Saving a byte over the more obvious `6X×$6X’¤¡X`
> 
> 
> 
. In fact, we don't need to make such a big modification. Therefore, this is an alternative approach to Jonathan Allan's answer, and, also, a resting place for my initial invalid 6-byter. :(
[Answer]
# [Perl 5](https://www.perl.org/), 54 bytes
```
$a=6;map$a*=$r=1+int rand$a,0..rand 6;say 1+int rand$r
```
[Try it online!](https://tio.run/##K0gtyjH9/18l0dbMOjexQCVRy1alyNZQOzOvRKEoMS9FJVHHQE8PxFIwsy5OrFRAkir6//9ffkFJZn5e8X9dX1M9A0MDIJ2UmQ5UAQA "Perl 5 – Try It Online")
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 16 bytes
```
⊞υ⁶Ｆ⊕‽⁶⊞υ⊕‽ΠυＩ⊟υ
```
[Try it online!](https://tio.run/##bYyxCoAgFAD3vsLxCbW6ODa1SX8gahioL57a778kaGu9O85FSw5tYja9RuizUFJPB5KArTgKOZQWPOy2eMygpJTiC3@8IfTdNeijGxtDZ2mw2trA4PVSzczLnR4 "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
⊞υ⁶
```
Push 6 to the predefined list.
```
Ｆ⊕‽⁶
```
Repeat a random number of times from 1 to 6...
```
⊞υ⊕‽Πυ
```
... push a random number between 1 and the product of the list to the list.
```
Ｉ⊟υ
```
Output the last number pushed to the list.
Alternative approach, also 16 bytes
```
≔⁶θＦ‽⁶≧×⊕‽θθＩ⊕‽θ
```
[Try it online!](https://tio.run/##bcyxCoAgEADQva9wvINaW5yiqSGI6AcOMxPyLJV@/xqirf3xzE7JRDpEupy9Y2hrdaGutpgUzMRrDNAiqpHOF8ze7QUWH2yu1cAm2WC52PXDF@I7TMlzgZ5ygX@GqEWkuY8H "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
≔⁶θ
```
Set the number of sides to 6.
```
Ｆ‽⁶
```
Repeat a random number between 0 and 5 times...
```
≧×⊕‽θθ
```
... multiply the number of sides by a random number from 1 to the number of sides.
```
Ｉ⊕‽θ
```
Print a random number from 1 to the number of sides.
[Answer]
# [Python 3](https://docs.python.org/3/), 76 bytes
```
from random import*
r=randint
a=6
for i in" "*r(0,5):a*=r(1,a)
print(r(1,a))
```
[Try it online!](https://tio.run/##K6gsycjPM/7/P60oP1ehKDEvBUhl5hbkF5VocRXZggQy80q4Em3NuNLyixQyFTLzlBSUtIo0DHRMNa0StWyLNAx1EjW5CoqAyjQgHM3//wE "Python 3 – Try It Online")
-2 bytes thanks to TFeld
[Answer]
# [R](https://www.r-project.org/), 43 bytes
```
s=sample
for(i in 1:s(k<-6))T=s(k<-k*T,1)
T
```
[Try it online!](https://tio.run/##K/r/v9i2ODG3ICeVKy2/SCNTITNPwdCqWCPbRtdMUzPEFszK1grRMdTkCvn/HwA "R – Try It Online")
`k` keeps track of the current number of faces on the die. Uses the fact that `T` is initialized as `1`.
I tried a few other things, but couldn't beat this simple, straightforward approach.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 10 bytes
```
6×X$6X’¤¡X
```
[Try it online!](https://tio.run/##y0rNyan8/9/s8PQIFbOIRw0zDy05tDDi/38A "Jelly – Try It Online")
### Explanation
```
       ¤   | Following as a nilad:
    6X     | - A random number between 1 and 6
      ’    | - Decrease by 1 (call this N)
6          | Now, start with 6
   $    ¡  | Repeat the following N times, as a monad
 ×         | - Multiply by:
  X        |   - A random number between 1 and the current total
         X | Finally, generate a random number between 1 and the output of the above loop
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), 41 bytes
```
r=6;rand(2..7).times{r*=$s=rand 1..r};p$s
```
[Try it online!](https://tio.run/##KypNqvz/v8jWzLooMS9Fw0hPz1xTryQzN7W4ukjLVqXYFiSsYKinV1RrXaBS/P8/AA "Ruby – Try It Online")
**Explanation**
```
r=6                                 # Set dice number to 6
rand(2..7).times{               }   # Repeat X times, where X=dice roll+1
                 r*=$s=rand 1..r    # Multiply dice number by a dice roll
                                    # Save the most recent dice roll
p$s                                 # Print last dice roll (this is why
                                    #  we did the last step one extra time)
```
[Answer]
# Java 10, ~~214~~ ~~93~~ 86 bytes
```
v->{int r=6,n=0;for(var d=Math.random()*6;d-->0;n*=Math.random(),r*=++n)n=r;return n;}
```
[Try it online](https://tio.run/##bZA9bsMwDIX3nILIJNmx4S4ZKig3SJYAXdoOquwkSmXK0B9QBD67K8lZCnQhQL5Hvg@8iyiae/@9SC2cg6NQ@NgAKPSDvQg5wCm3ANrgFSR5M6qHSFmazZtUnBdeSTgBAoclNodH2gTL9zvkHbsYS6Kw0POj8LfWCuzNSGi1Z33THDqG1V9hZyte10iRW2YHHywCsnlhOWkKXzolPQNj5hgTLDl7q/D6/gmCrqQFwGjtEtFLx8rs/OP8MLYm@HZKdq@RFEu9hTUbkjQF714/cEvXnQyfbylerAxUYQZa1H9vYisJBq3p80Hz8gs) or [try it online with additional print-lines to see the steps](https://tio.run/##bVE9b8IwFNz5FU@ebPIhsjBgmaE7qCpSF8rgJIaaOi/IcSJViN@ePgekqhWLJd@d7707n/Wgs3P9NVZOdx1stMXrDMBiMP6oKwPbeJ0AqPh7a2sYhCToNqOjCzrYCraAoGAcsvU16rxapqgWctAearXR4TP3Guu24WK@lMfW8913F0yTt33IL56eOOTs1dvGwEtfls6Ab51bAUs4kYLXSSGErLNsvZCo7thfW0@K9IkritTPFYr/FGdvNIFSAVmcDOyLlCU@YQcaKqQ3ofcIKG@jjDEvfeko5iPtEEtoqCi@C@R12h9Ai9@W4uod1VEs5IQ92WqSJAzu6wNRlz50qw9k4v4mdhS9rJqkEuyUHcTEPvXEvOLYOycev3MbfwA).
-128 bytes by using `int` instead of `java.math.BigInteger`. \$6^{32}\$, the largest possible result, doesn't fit inside an `int` nor `long`, which is why `BigInteger` was used initially. OP allowed to use `int` and assuming it's infinitely large, so that saved more than 125 bytes here. :) ([Here the previous **214 bytes** version using `BigIntegers`.](https://tio.run/##bZFBawIxEIXv/orBU2LdqBehhrVQ6KFQFWrppe0hbuIam02W7GSLiL/dJqtQD70EJvPyHt/LXrQi28vvs65q5xH2cWaVwB0bcIDRCO4m94AONgdUWeGCxV5hRNPAQmh77AFoi8pvRaFgmUa4cXjU5XPclspDQd6dltBSHjWnXjwaFKgLWIKFHM5tNj/eyDG3wZihz5G1wgS12pIp5VvnSSs8yHyR7L2w0lWEDqZcZtl8zDHKhZQE2Wr5RONrOR8/eFYFg7o2B4J0hjSZcBID1A/8JRLPNhpflC1xR@gwLTuOgNqw12sQpaxwVS28enPE05hIuVcYvAXPT2eesOqwMRHrStcm6Co2RdbotS0/vkDQS02xN/DOmCbiT8a8u1sfGlQVcwFZHeVoLOkkd324wEJc1QGb2aft08ubxJO8dN5JOeiuC6Dd9l9PywqS@qXX3zidfwE))
**Explanation:**
```
v->{                        // Method with empty unused parameter & integer return-type
  int r=6,                  //  The range in which to roll, starting at 6
      n=0;                  //  The roll itself (which must be initialized, therefor is 0)
  for(var d=Math.random()*6;//  Roll the Prime Bubble Dice
      d-->0                 //  Loop that many times:
      ;                     //    After every iteration:
       n*=Math.random(),    //     Roll a random dice in the range [0, n)
       r*=++n)              //     Increase `n` by 1 first with `++n`, so the range is [1,n]
                            //     And then multiply `r` by `n` for the new range
    n=r;                    //   Set `n` to `r`
  return n;}                //  After the loop, return `n` as result
```
[Answer]
# [PHP](https://php.net), 59 bytes
```
$r=$q=rand(1,$s=6);while($l++<$q)$r=rand(1,$s*=$r);print$r;
```
expanded:
```
$r=$q=rand(1,$s=6);
while($l++<$q)$ 
    r=rand(1,$s*=$r);
print$r;
```
Not sure if I'm supposed to include the open tag.
On my machine, it crashes if `$s*$r` is too large, so it doesn't print on `$q>=5` sometimes... because the numbers get so big. Not sure of a fix.
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 14 bytes
```
uhO=*|Z6GO6hO6
```
[Try it online!](https://tio.run/##K6gsyfj/vzTD31arJsrM3d8sw9/s/38A "Pyth – Try It Online")
```
uhO=*|Z6GO6hO6   
         O6      Random number in range [0-6)
u                Perform the following the above number of times...
           hO6   ... with starting value G a random number in range [1-6]:
    *   G          Multiply G with...
     |Z6           The value of Z, or 6 if it's the first time through (Z is 0 at program start)
   =  Z            Assign the above back into Z
  O                Random number in range [0-Z)
 h                 Increment
                 Implicit print result of final iteration
```
[Answer]
# [C# (.NET Core)](https://www.microsoft.com/net/core/platform), 136 bytes
```
class A{static void Main(){var r=new System.Random();int i=r.Next(6),j=6;while(i-->0)j*=1+r.Next(j);System.Console.Write(r.Next(j)+1);}}
```
[Try it online!](https://tio.run/##PcuxCsIwEADQX8mYWBPs0iVEEGcddHAO6YEX0gRyR6uUfntcivPjBdKhVGgtJE8kLiuxZwxiLjiKm8cs1Tr7KqrLsIjnlxgm8/B5LJNUFjMLdNXc4cNyUMfoBru8MYFErc8nFQ@u73aOyu79WjKVBOZVkUH@ueuV3bbWfg "C# (.NET Core) – Try It Online")
I'm *pretty* sure this works, given the assumption of infinite integer length that we're fond of here. If I have to actually handle the overflow, I'd need to bust out an entirely different class.
[Answer]
# [Julia 1.0](http://julialang.org/), 60 bytes
```
g(b=big(6),r=rand)=(for i in 1:r(0:5) b=b*r(1:b) end;r(1:b))
```
`b=big(6)` makes it work with arbitrary sized integers
[Try it online!](https://tio.run/##yyrNyUw0rPj/P10jyTYpM13DTFOnyLYoMS9F01YjLb9IIVMhM0/B0KpIw8DKVFMBqEarSMPQKklTITUvxRrC1PzvUJyRX66QrqH5HwA "Julia 1.0 – Try It Online")
[Answer]
# [Gaia](https://github.com/splcurran/Gaia), 13 bytes
```
:(ṛ×
6₅ṛ(↑ₓ(ṛ
```
[Try it online!](https://tio.run/##S0/MTPz/30rj4c7Zh6dzmT1qagWyNB61TXzUNBkk@P8/AA "Gaia – Try It Online")
]