[Question]
  [
Remember the kids game, ['Duck, Duck, Goose'](https://en.wikipedia.org/wiki/Duck,_duck,_goose)? No? Me neither.
### The challenge
* Print the word 'duck' on individual lines an indeterminate amount of times.
* Print the word 'goose'.
* Your program ends.
### The rules
* Attempt to play the game in the fewest bytes.
* There must be at least one duck.
* There must be exactly one goose, at the end of the list.
* There must be exactly one bird on each line. No empty lines.
* The case of the outputted strings is irrelevant.
* White-space within a line is fine.
* Your program must finish.
* Your program must not consistently produce the same number of ducks.
Have fun!
---
Please note: This question is not a duplicate of [Shortest code to produce non-deterministic output](https://codegolf.stackexchange.com/questions/101638/shortest-code-to-produce-non-deterministic-output)
Reasons include:
* The association to a childrens' game
* The defined start and end requirements of the result string. There is no specified output in the other challenge.
* Answers For the other, non-duplicate challenge are in a single-digit number of bytes. The average for this one is around 30, or there about.
* By the amount of overlap between this challenge and that one, any code-golf question including the 'random' tag is a duplicate. Should we delete them all?
* The code answers for this challenge would match the other challenge (in a ridiculously bloated way), but the answers to that challenge would not match this one.
  
[Answer]
# [Operation Flashpoint](https://en.wikipedia.org/wiki/Operation_Flashpoint:_Cold_War_Crisis) scripting language, 48 bytes
```
f={s="duck\n";s+([s,""]select random 1)+"goose"}
```
Always prints either one or two ducks.
`random 1` returns a (floating point) number between 0 and 1. That number is passed as an argument to `select` along with the array `[s,""]`. The random number is then rounded to the nearest integer (either 0 or 1), and the array element at that index is selected from the array.
**Call with:**
```
hint call f
```
**Output:**
[![](https://i.stack.imgur.com/54VWS.png)](https://i.stack.imgur.com/54VWS.png)
**Alternative 56 bytes version:**
```
f={s="duck\n";format[s+"%1goose",[s,""]select random 1]}
```
[Answer]
## World of Warcraft 81 Bytes
Here's a macro that you can run in World of Warcraft.
```
/run for x=1,random(1,9) do SendChatMessage("Duck") end; SendChatMessage("Goose")
```
[Answer]
# Minecraft <1.13, ~~72~~ 54 bytes
Sorry, I had to.
## Instructions:
* Create a new Minecraft world in Creative Mode
* Find the save folder for that world, and place the following code in `data/functions/minecraft/ddg.mcfunction`
* Run `/function ddg` in the game console
## How it works:
Outputs the word "duck" for every entity in the world, then outputs the word "goose". Since entities are constantly spawning and despawning, the number of "duck"s will not be consistent. I used `tellraw` instead of the much shorter `say` because `say` outputs the name of the entity, while `tellraw` outputs exactly what it is told.
```
execute @e ~ ~ ~ tellraw @a "duck"
tellraw @a "goose"
```
## Screenshot
[![enter image description here](https://i.stack.imgur.com/pVU4g.png)](https://i.stack.imgur.com/pVU4g.png)
Edit: Changed {"text":"duck"} to just "duck" (and the same with "goose")
[Answer]
# JavaScript, ~~45~~ ~~44~~ ~~42~~ ~~39~~ 37 bytes
Has the potential to produce an overflow error.
```
f=_=>`duck
${new Date%2?f():`goose`}`
```
---
## Test it
```
o.innerText=(
f=_=>`duck
${new Date%2?f():`goose`}`
)()
```
```
<pre id=o></pre>
```
[Answer]
# [Octave](https://www.gnu.org/software/octave/), ~~38~~ 33 bytes
This is not the shortest (it's 36 bytes), but it's my favorite. The explanation is in the bottom.
```
disp(['duck '+~(1:1/rand)';'goose'])
```
[Try it online!](https://tio.run/##y08uSSxL/f8/JbO4QCNaPaU0OVtBXbtOw9DKUL8oMS9FU91aPT0/vzhVPVbz/38A "Octave – Try It Online")
---
Some shorter variations:
This works in principle (33 bytes), but the online interpreters times out:
```
disp(['duck '+~(1:now)';'goose'])
```
Adding some bytes to make the output shorter makes it 35 or 36 bytes:
```
disp(['duck '+~(7e5:now)';'goose'])   % Works on octave-online.net
disp(['duck '+~(7.3e5:now)';'goose']) % Works on tio.run
```
### Explanation:
I'll just explain the last random one. The others are similar, but uses the number of days since **January 1st, 0000** until today.
`rand` returns a random number on the interval **(0, 1)**. Thus, `1/rand` returns a number larger than **1**. Since a range `1:f`, where `f` is a random float larger than **1** is identical to `1:floor(f)`, `1:1/rand` creates a range **1 .. x**, where **x >= 1**.
I'll try to explain this as if Octave was a stack based language. 
```
      'duck '                           % Push the string 'duck ' to the stack
               (1:1/rand)               % Push a vector 1... floor(1/rand)
              ~(1:1/rand)'              % Negate the vector (making it all zeros)
                                        % and transpose it.
             +                          % Add 'duck ' with the vertical vector of zeros
                                        % to implicitly duplicate the string r times
     [                    ;'goose']     % Push the string 'goose' and concatenate
                                        % vertically with the rest
disp(                              )    % Display it all.
```
[Answer]
# Z Shell (+ wget & Netpbm), ~~168~~ ~~160~~ ~~150~~ ~~148~~ ~~145~~ ~~135~~ 120 bytes
```
d(){wget -O- bit.ly/$1|jpegtopnm|pamscale -w 64 -h 64};d DckDkGo|pnmtile 64 $[(RANDOM&7+1)*64]|pnmcat -tb - <(d g005eGG)
```
Not the shortest solution, but I felt like giving a twist of sorts to this challenge (inspired by [@AlexG's solution to this other problem](https://codegolf.stackexchange.com/a/159718/79247)).
This script generates a PPM image containing between 1-8 pictures of ducks and a picture of a goose at the bottom on standard output. It downloads the two source pictures from Wikipedia, so internet access is necessary for it to work.
Sample output converted to JPEG through *pnmtojpeg*:
[![enter image description here](https://i.stack.imgur.com/MvNnS.jpg)](https://i.stack.imgur.com/MvNnS.jpg)
[Answer]
# [Python 2](https://docs.python.org/2/), 36 34 bytes
```
print"duck\n"*((id(id)%5)+1),"goose"
```
[Try It Online!](https://tio.run/##K6gsycjPM/r/v6AoM69EKaU0OTsmT0lLQyMzBYg0VU01tQ01dZTS8/OLU5X@/wcA)
Suggestion by [Kevin Cruijssen](https://codegolf.stackexchange.com/users/52210/kevin-cruijssen) gets us to 34 bytes:
```
print"duck\n"*-~(id(id)%5),"goose"
```
[Answer]
# [Perl 5](https://www.perl.org/), 20 bytes
First a practical 26 bytes:
Ducks 1 to 9 times before being goosed.
```
say"Duck
"x(1+$^T%9),Goose
```
[Try it online!](https://tio.run/##K0gtyjH9/784sVLJpTQ5m0upQsNQWyUuRNVSU8c9P7849f//f/kFJZn5ecX/dX1N9QwN9AwA "Perl 5 – Try It Online")
But if you have lots of memory and time this 20 byte version (as suggested by [Chris](https://codegolf.stackexchange.com/users/58834/chris)) works too:
```
say"Duck
"x$^T,Goose
```
This also assumes the [Year 2038 Problem](https://en.wikipedia.org/wiki/Year_2038_problem) will be solved for [Perl 5](https://www.perl.org/), otherwise it will be invalid for 1 second 20 years hence.
[Answer]
# [Bash](https://www.gnu.org/software/bash/), 39 38 37 bytes
```
sed s/[0-9]/duck\\n/g<<<$RANDOM\goose
```
[Try it online!](https://tio.run/##S0oszvj/vzg1RaFYP9pA1zJWP6U0OTsmJk8/3cbGRiXI0c/F3zcmPT@/OPX/fwA "Bash – Try It Online")
Prints a number of ducks equal to the number of digits in an integer uniformly distributed on [0,32767] (so, more often than not, five ducks (a good number of ducks)).
-1 byte each thanks to @Chris and @sch pointing out pairs of quotes that weren't pulling their weight.
[Answer]
# [R](https://www.r-project.org/), 35 bytes
```
cat(rep("duck
",rexp(1)+1),"goose")
```
[Try it online!](https://tio.run/##K/r/PzmxRKMotUBDKaU0OZtLSacotaJAw1BT21BTRyk9P784VUnz/38A "R – Try It Online")
`rexp()` produces a random number from an exponential decay function. `+1` to ensure at least one duck. All lines after the first include a leading space (which is the default separator for `cat`) but this is allowed.
[Answer]
# Pure Bash (no external utilities), 25
Based on [@SophiaLechner's answer](https://codegolf.stackexchange.com/a/157940/11259), this also prints *a good number of ducks*.
@OlivierDulac's idea to use the script shell PID as stored in the `$` parameter saves 5 bytes.
```
echo "${$//?/duck
}"goose
```
[Try it online](https://tio.run/##S0oszvj/PzU5I19BSaVaRV/fXj@lNDmbq1YpPT@/OPX/fwA).
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 13 bytes
```
2X“¢;ÆS»ẋ“ʋ¢»
```
[Try it online!](https://tio.run/##y0rNyan8/98o4lHDnEOLrA@3BR/a/XBXN5B3qvvQokO7//8HAA "Jelly – Try It Online")
Explanation:
```
2X“¢;ÆS»ẋ“ʋ¢»
2X             Random number (1 or 2)
  “¢;ÆS»       Compressed string equivalent to "duck\n"
        ẋ      Repeat the "duck\n" that random number of times
         “ʋ¢»  Compresses string equivalent to "goose"
               Implicitly concatenated and returned
```
---
More readable version: [Try it online!](https://tio.run/##y0rNyan8/98oQuFRw5yU0uTsQ9seNcx9uKsbxE/Pzy9OBXL//wcA "Jelly – Try It Online")
Will always return 1 or 2 ducks.
[Answer]
# [Ruby](https://www.ruby-lang.org/), 30 bytes
```
puts"duck
"*rand(1..9)+"goose"
```
[Try it online!](https://tio.run/##KypNqvz/v6C0pFgppTQ5m0tJqygxL0XDUE/PUlNbKT0/vzhV6f9/AA "Ruby – Try It Online")
Note: really 31 bytes without the `\n` cheat.
[Answer]
# Bash + Coreutils, ~~36~~ 27 bytes
```
yes duck|sed $$q;echo goose
```
Prints too many ducks (between 2 and `cat /proc/sys/kernel/pid_max`), then one goose.
Saved nine bytes thanks to Digital Trauma and Olivier Dulac.
[Try it online!](https://tio.run/##S0oszvj/vzK1WCGlNDm7pjg1RUFFpdA6NTkjXyE9P7849f9/AA) (but keep in mind that it may get truncated occasionally)
Same length, but with no `echo`:
```
yes duck|sed $${agoose'
q}'
```
[Try it online!](https://tio.run/##S0oszvj/vzK1WCGlNDm7pjg1RUFFpToxPT@/OFWdq7BW/f9/AA)
`a` is the append command in `sed`, and `q` quits. Both only run on the line `$$`, which corresponds to the PID.
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), ~~35~~ ~~30~~ 28 bytes
```
,"duck"*((Random)+1)
"goose"
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/X0cppTQ5W0lLQyMoMS8lP1dBNzdRwVRT21CTSyk9P784Ven/fwA "PowerShell – Try It Online") (modified version)
Generates an array of [`Get-Random`](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/get-random?view=powershell-6) number of items. It might take a while. This adds a `+1` to ensure we get at least one `duck`. The modified version also includes a `-ma`ximum flag of `5` so you can see the program works as expected (the modified version will print 1, 2, 3, or 4 `duck`s before the `goose`).
The array and the solitary `goose` string is left on the pipeline, and the implicit `Write-Output` gives us newline-separated values for free.
You don't know how difficult it was for me to not change the last line to ["gray duck"](https://en.wikipedia.org/wiki/Duck,_duck,_goose#Duck,_Duck,_Gray_Duck) ...
[Answer]
# [Python 2](https://docs.python.org/2/), 54 bytes
```
from random import*
print"duck\n"*randint(1,9)+"goose"
```
**[Try It Online!](https://tio.run/##K6gsycjPM/r/P60oP1ehKDEvBUhl5hbkF5VocRUUZeaVKKWUJmfH5ClpgSSBfA1DHUtNbaX0/PziVKX//wE "Python 2 - Try It Online!")**
[Answer]
# [C# (Visual C# Interactive Compiler)](http://www.mono-project.com/docs/about-mono/releases/5.0.0/#csc), 55 bytes
```
Write("{"+new Random().Next(2)+"}{0}goose","duck\n","")
```
[Try it online!](https://tio.run/##Sy7WTS7O/P8/vCizJFVDqVpJOy@1XCEoMS8lP1dDU88vtaJEw0hTW6m22qA2PT@/OFVJRymlNDk7Jg/IUNL8/x8A "C# (Visual C# Interactive Compiler) – Try It Online")
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), ~~24~~ 21 bytes
-3 bytes thanks to Erik the Outgolfer
```
"duck"ẉ4ṙ0∧"goose"w∨↰
```
[Try it online!](https://tio.run/##AS0A0v9icmFjaHlsb2cy//8iZHVjayLhuok04bmZMOKIpyJnb29zZSJ34oio4oaw//8 "Brachylog – Try It Online")
In celebration of the [Language of the month](https://codegolf.meta.stackexchange.com/questions/14917/language-of-the-month-for-march-2018-brachylog), my first brachylog post. The control flow in this language is cool.
How it works:
```
"duck"ẉ4ṙ0∧"goose"w∨↰
"duck"ẉ                 print duck with a new line
       4ṙ               choose a random number in the range is [0, 4]
         0              verify it equals zero
          ∧             and (short circuits)
           "goose"w     print goose without a newline
                   ∨    or (if it did not equal zero)
                    ↰   repeat the procedure
```
[Answer]
## [Geometry Dash World 2.2 Editor](https://www.google.com/search?q=gdw+2.2+editor&rlz=1C1CHBF_enUS698US698&oq=gdw+2.2+editor&aqs=chrome..69i57j0l2.6191j0j7&sourceid=chrome&ie=UTF-8) - 4 objects
[![Picture of Geometry Dash Level](https://i.stack.imgur.com/nnyrf.png)](https://i.stack.imgur.com/nnyrf.png)
**Explanation:**
The BG trigger is the current 2.2's random trigger, so it either toggles the Group ID 1 or 2.
The first "DUCK" has a group id of 1, which makes it have a 50% chance of being removed or not (toggled).
There is no object with the Group ID 2 in this level, so there is a 50% chance of 2 "DUCK"s being displayed.
**How to Reproduce this:**
The first "DUCK" has a Group ID of 1.
[![enter image description here](https://i.stack.imgur.com/wp9TZ.png)](https://i.stack.imgur.com/wp9TZ.png)
Goose and 2nd duck don't have a Group ID
[![enter image description here](https://i.stack.imgur.com/oh88O.png)](https://i.stack.imgur.com/oh88O.png)
Inside the random trigger.
[![enter image description here](https://i.stack.imgur.com/NnCnU.png)](https://i.stack.imgur.com/NnCnU.png)
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~15~~ 14 bytes
```
'Ðœ₁Ωи`.•zíΘ•»
```
[Try it online!](https://tio.run/##MzBNTDJM/f9f/fCEo5MfNTWeW3lhR4Leo4ZFVYfXnpsBpA/t/v8fAA "05AB1E – Try It Online")
Will print 2, 5 or 6 ducks and then goose.
-1 byte thanks to @Emigna using ' for a single compressed word (duck)
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/), 22 bytes
*1 byte saved thanks to @EriktheOutgolfer*
```
'Goose'⍪⍨(?9)5⍴'Duck '
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///X909P784Vf1R76pHvSs07C01TR/1blF3KU3OVlDHLwsA "APL (Dyalog Unicode) – Try It Online")
[Answer]
## [Retina](https://github.com/m-ender/retina/wiki/The-Language), 17 bytes
```
?\\K`duck
K`goose
```
[Try it online!](https://tio.run/##K0otycxLNPz/3z4mxjshpTQ5m8s7IT0/vzj1/38A "Retina – Try It Online")
[Try it online!](https://tio.run/##K0otycxLNPz/P8Y7IaU0OZvLXjvGPYHLOyE9P7849f9/AA "Retina – Try It Online")
Prints 1 or 2 ducks, with equal probability.
### Explanation
```
?\\K`duck
```
Set the working string to `duck` and print it with a trailing linefeed (`\`). Then this is wrapped in another output stage, but this one has the random flag (`?`) applied to it, so it only prints with a probability of 50%.
```
K`goose
```
Replace the `duck` with `goose`, which is printed implicitly at the end of the program.
Here's a fun alternative which prints 1 duck with 50% probability, 2 ducks with 25%, 3 ducks with 12.5%...:
```
\K`duck
?+\G`
K`goose
```
[Answer]
# Vim (script) on Linux, ~~46~~ 43 bytes (~~49~~ 46 with `:` at start of line)
```
.!date +0\%N\%s6
s/6.*/goose
s/\d/duck\r/g
```
Executed as `vim -S filename` or pasted into running `vim` with `:` before each line.
[Answer]
# [><>](https://esolangs.org/wiki/Fish), ~~31~~ 22 bytes
```
"duck"a>x
r"esoog"<>o<
```
[Try it online!](https://tio.run/##S8sszvj/XymlNDlbKdGugqtIKbU4Pz9dycYu3@b/fwA "><> – Try It Online")
-9 bytes based on Not a tree's revision
[Answer]
# [Befunge 98](http://www.quirkster.com/iano/js/befunge.html), ~~38~~ ~~30~~ 25 bytes
```
"esooG"v>:#,_@
"Duck"a<?<
```
[Try it online!](https://tio.run/##S0pNK81LT9W1tNAtqAQz//9XSi3Oz3dXKrOzUtaJd@BScilNzlZKtLG3@f8fAA "Befunge-98 (PyFunge) – Try It Online")
* Thanks @JoKing for stripping the useless trampoline
* Switching to Befunge 98 for shorter new line - now `Duck` fits within a single string
[Answer]
# [T-SQL](https://docs.microsoft.com/en-us/sql/t-sql/language-reference), ~~70 44~~ 43 bytes (Many ducks)
```
while rand()<.9print'duck'print'duck
goose'
```
Thanks @Zac Faragher!
  
## Revised Version, ~~54 43~~ 40 bytes (1 or 2 ducks)
Thanks @BradC!
```
if rand()<.5print'duck'print'duck
goose'
```
  
I can't seem to get this to run properly in [SQL Fiddle](http://sqlfiddle.com/#!18/15ff7/4), but it works just fine in LINQPad and SSMS. 
Not sure if this is a known limitation of SQL Fiddle or I'm just doing something wrong
[Answer]
# Powershell - ~~31~~ 30 bytes
**Warning**: You're most likely going to end up with a lot of ducks. `Random` includes the values of 0 to `Int32.MaxValue` so, depending on how random you're number is, this could be a lot of quacking.
```
1..(Random)|%{"Duck"};"Goose"
```
[Answer]
# [Fission](https://github.com/C0deH4cker/Fission), ~~24~~ 19 bytes
```
R"duck"N#
"goose"*[
```
[Try it online!](https://tio.run/##S8ssLs7Mz/v/P0gppTQ5W8lPmUspPT@/OFVJK/r/fwA "Fission – Try It Online")
-5 bytes thanks to Martin Ender
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 21 bytes
```
1ṙ+₁;"Duck
"j₍,"Goose
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/r/3/Dhzpnaj5oarZVcSpOzuZSyHjX16ii55@cXp/7//z8KAA "Brachylog – Try It Online")
Hey, language of the month going inactive, let's kick things up a little!
[Answer]
# [Befunge](http://www.quirkster.com/iano/js/befunge.html)
~~57~~ 35 bytes (perimeter of the entire field is ~~19x3~~ 17x2 charachters) Thanks to karhell for the improvement.
```
55+"kcud",,,,,#v?
  @,,,,,"goose"<
```
The second line puts duck and a newline on the stack (backwards) and outputs it as a string. After that 75% chance of going back to the start and printing duck again, 25% (when question mark decides to go down) to print goose and stop.
]