[Question]
  [
Have you ever wanted to ask the compiler "Why?" Most of us have been frustrated when the code isn't working as it should. Mathworks has therefore implemented a nice little function, `why`, that answers the question. To give a few examples from MATLAB:
```
why
The programmer suggested it.
why
To fool the tall good and smart system manager.    
why(2)
You insisted on it.
why(46)
Bill insisted on it.
```
Your task is to implement the `why` function in your language. The function should work with and without an input argument (alternatively use input `0` or `-1`). The function must be named `why` (or, writing `why(n)` in STDIN should result in the appropriate string being printed). 
If no argument is given, or the argument is zero or negative, the output string should be a random, valid phrase. So, there should be a function `why`, `why()`, `why(0)` or `why(-1)` that returns a random sentence. 
If an input argument, `n` is given (function argument, not STDIN), the output should be the n'th string (defined below). So, `why(1)` should always output (print/display) the same result.
The sentences are built up as follows (Type 1, Type 2 and Special). All sentences end with `!`.
```
"Person" "ending" !
"Verb" "adjective" "Person" !
A list of special cases
```
The list of persons:
```
Stewie
Peter
Homer
The programmer
The system manager
You
```
The list of endings:
```
suggested it
insisted on it
did it
```
The list of verbs are:
```
To fool
To satisfy
To please
```
The list of adjectives:
```
the smart
the bald
the tall
the rich
the stupid
```
The list of special cases:
```
How should I know?
Stop asking!
Don't ask!
```
The way to select a numbered one is:
**Type of sentences:**
```
Odd number => Type 1
Even number => Type 2
n % 7 = 0 => Type 3 (% is the modulus operator)
```
**Names:** The nth name is defined using modulus (%).
```
n = 1:   1 % 7  => Stewie
n = 2:   2 % 7  => Peter
...
n = 6:   6 % 7  => You
n = 7:   7 % 7  => How should I know?
n = 11:  11 % 7 => The programmer
n = 14:  14 % 7 => Stop asking!
n = 21:  21 % 7 => Don't ask!
```
**Endings:** The nth ending is also defined using the modulus. Assume the endings (1, 2 and 3) are listed like `(1 2 2 3)`. As the numbers are always odd, use `((n+1)/2 % 4)`
```
n = 1:    ((1+1)/2 % 4)  => suggested it
n = 3:    ((3+1)/2 % 4)  => insisted on it
n = 13:   ((13+1)/2 % 4) => did it
```
**Adjectives:** The nth adjective is defined using the modulus. As the numbers are always even, use: `(n % 10)/2`
```
n = 2:   (2 % 10)/2 => Smart
n = 6:   (6 % 10)/2 => The tall
...
```
**Verbs:** The nth verb is also defined using the modulus. Assume the verbs (1, 2 and 3) are listed like `(1 2 2 3)` As the numbers are always even for verbs, use `(n % 8) / 2`
```
n = 2:   (2 % 8)/2 => To fool
n = 4:   (4 % 8)/2 => To satisfy
n = 6:   (6 % 8)/2 => To satisfy
n = 8:   (8 % 8)/2 => To please
```
Now, the way to create a random one should be fairly simple, simply select a random `n`.
Some examples:
```
why
You suggested it!
why
To fool the tall Homer!
why
Don't ask!
why(1)
Stewie suggested it!
why(14)
Stop asking!
why(8)
To please the rich Stewie!
```
Standard code golf rules apply. A winner will be selected one week from the day the challenge was posted.
  
[Answer]
# JavaScript (ES6) 345
Not sure about the numbers, but here is my attempt.
Test running the snippet below in an EcmaScript compliant browser.
```
why=n=>(n<1?n=Math.random()*840|0:0,s="suggested,insisted on,did,fool,satisfy,please,stupid,smart,bald,tall,rich,Don't ask!,How should I know?,Stop asking!,Stewie,Peter,Homer,programmer,system manager,You".split`,`,n%7?(p=s[n%7+13],n&1?(p>'a'?'The ':'')+p+` ${s['2011'[-~n/2%4]]} it!`:`To ${s['5344'[n%8/2]]} the ${s[n/2%5+6]} ${p}!`):s[11+n%3])  
for(o='',i=0;++i<1e3;)o+=i+':'+why(i)+'\n';O.innerHTML=o
function test() { R.innerHTML=why(+I.value) }
// Less golfed
WHY=n=>(
  n=n<1?Math.random()*999|0:n,
  s=["suggested", "insisted on", "did", "fool", "satisfy", "please",
     "stupid", "smart", "bald", "tall", "rich",
     "Don't ask!", "How should I know?", "Stop asking!",
     "Stewie", "Peter", "Homer", "programmer", "system manager", "You"],
  n%7
    ? ( p=s[n%7+13],
        n&1
        ? (p>'a'?'The ':'')+p+` ${s['2011'[-~n/2%4]]} it!`
        : `To ${s['5344'[n%8/2]]} the ${s[n/2%5+6]} ${p}!`)
    : s[11+n%3]
)  
```
```
#O { height:300px; width:50%; overflow:auto }
#I { width:2em }
```
```
Why(<input id=I>)<button onclick=test()>-></button><span id=R></span>
<pre id=O>
```
[Answer]
# C#, 502 bytes
This project needs to have the **AssemblyName** set to **why** which will produce an executable with the correct name.
Fully golfed:
```
using System;class W{static void Main(string[]i)int n=i.Length>0?int.Parse(i[0]):new Random().Next();string[]s={"Don't ask!","How should I know?","Stop asking!"},v={"To please ","To fool ","To satisfy ",null},a={"the stupid","the smart","the bald","the tall","the rich"},p={"","Stewie","Peter","Homer","The programmer","The system manager","You"},e={"suggested it!","insisted on it!",null,"did it!"};Console.Write(n%7<1?s[n%3]:n%2<1?(v[n%8/2]??v[2])+a[n%10/2]+" {0}!":"{0} "+(e[n/2%4]??e[1]),p[n%7]);}}
```
Indentation and new lines for clarity:
```
using System;
class W{
    static void Main(string[]i)
        int n=i.Length>0
            ?int.Parse(i[0])
            :new Random().Next();
        string[]
            s={"Don't ask!","How should I know?","Stop asking!"},
            v={"To please ","To fool ","To satisfy ",null},
            a={"the stupid","the smart","the bald","the tall","the rich"},
            p={"","Stewie","Peter","Homer","The programmer","The system manager","You"},
            e={"suggested it!","insisted on it!",null,"did it!"};
        Console.Write(
            n%7<1
                ?s[n%3]
                :n%2<1
                    ?(v[n%8/2]??v[2])+a[n%10/2]+" {0}!"
                    :"{0} "+(e[n/2%4]??e[1]),
            p[n%7]
        );
    }
}
```
Example input/output:
```
>Why
To fool the bald Homer!
>Why 1
Stewie suggested it!
```
[Answer]
# Powershell ~~437~~ ~~461~~ 453 Bytes
Edit: Missed the duplicated verbs
Splitting between the corpus and the calculations for byte-count
* 267 Bytes = Pre-coded text (excluding `to`,`the`,`it` and `!` since they have fixed places).
* 186 Bytes = calculation
Sets default argument to 0 if not specified. If argument is `<1` then it gets a random number `<99` `fn:1` and reruns. Technically this means `-50` will work as well, being treated as a random case.
```
function why{param($b=0)$p=@('Stewie','Peter','Homer','The programmer','The system manager','You');$e=@('did','suggested','insisted on','insisted on');$v=@('please','fool','satisfy','satisfy');$a=@('stupid','smart','bald','tall','rich');$s=@("Don't ask!",'How should I know?','Stop asking!');if($b-le0){why(Get-Random 99)}elseif(!($b%7)){$s[$b/7%3]}else{$n=$p[$b%7-1];if($b%2){"$n $($e[($b+1)/2%4]) it!"}else{"To $($v[$b%8/2]) the $($a[$b%10/2]) $n!"}}}
```
Explanation:
```
# Any -1 in calculations is to account for arrays starting at index 0
# Final key placed in position 0 for indexing (4%4 = 0)
# Powershell 1 = True, 0 = False
if($b-le0){why(Get-Random 99)}          # If not positive, choose random number
elseif(!($b%7))                         # $b%7 means special so use that
  {$s[$b/7%3]}                          # Divide by 7 and find modulo, use that phrase.
else{$n=$p[$b%7-1]                      # Get the correct person (Used in both types). 6 max
if($b%2){"$n $($e[($b+1)/2%4]) it!"}    # Create type 1 sentence
else{"To $($v[$b%8/2]) the $($a[$b%10/2]) $n!"} # Type 2
```
`fn:1` 99 Chosen to save a byte. If there are more than 99 possible sentences above (did not calculate) increase to 999 or 9999 as applicable (+1/2 bytes)
[Answer]
# MUMPS, 379 bytes
```
f(s,i) s:'i i=$L(s,"^") q $P(s,"^",i)
why(n) s:'n n=$R(840) s p="Stewie^Peter^Homer^The programmer^The system manager^You",e="suggested^insisted on^did",v="fool^satisfy^please",a="smart^bald^tall^rich^stupid",s="How should I know?^Stop asking!^Don't ask!" q:n#7=0 $$f(s,n#3) q:n#2 $$f(p,n#7)_" "_$$f(e,n+1/2#4)_" it!" q "To "_$$f(v,n#8/2)_" the "_$$f(a,n#10/2)_" "_$$f(p,n#7)_"!"
```
When no input is given, a random number in 0..839 is generated. 
Usage:
```
>w $$why(15)
Stewie did it!
>w $$why()
Don't ask!
```
MUMPS's left-to-right evaluation strategy saves a good few bytes on parentheses here. 
Side note: see those strings that look like `"foo^bar^baz^qux"`? Those are so-called "delimited strings", and are the standard way of storing lists that fit within the maximum string size limit, since MUMPS does not actually have lists/arrays (or, indeed, any data structures besides trees). For lists too large to fit in a single string, we instead use trees of depth 1 and put the values on the leaves of the tree. Fun!
[Answer]
# Emacs Lisp 473 Bytes
```
(defun why(n)(if(and n(> n 0))(let*((p'(t"Stewie""Peter""Homer""The programmer""The system manager""You"))(e'("did""suggested""insisted on""insisted on"))(v'("please""fool""satisfy""satisfy"))(a'("stupid""smart""bald""tall""rich"))(s'("Don't ask!""How should I know?""Stop asking!"))(q(nth(% n 7)p)))(cond((=(% n 7)0)(nth(%(/ n 7)3)s))((=(% n 2)1)(format"%s %s it!"q(nth(%(/(1+ n)2)4)e)))(t(format"To %s the %s %s!"(nth(/(% n 8)2)v)(nth(/(% n 10)2)a)q))))(why(random 99))))
```
Largest 'waste' is probably the `format`,`%s`... sections. If variables could be inlined into the strings without the specification it would save 10 bytes on `%s` and another 12 on `format`
[Answer]
# Ruby ~~396~~ ~~378~~ 372 bytes
I'm sure this is not golfed to the max.
```
p=%w[a Stewie Peter Homer The\ programmer The\ system\ manager You]
why=->n{n<1 ? why[rand(99)+1]:n%7<1 ? $><<%w[a How\ should\ I\ know? Stop\ asking! Don't\ ask!][n/7]:n%2<1 ? $><<'To '+%w[fool satisfy satisfy please][n%8/2-1]+' the '+%w[smart bald tall rich stupid][n%10/2-1]+' '+p[n%7]+?!:$><<p[n%7]+' '+%w[a suggested insisted\ on insisted\ on did][(n+1)/2%4]+' it!'}
```
Edit: I've just realized that I don't know operator precedence. Oh well..
[Answer]
## CJam, 281 bytes
```
99mrqi_])0>=i:A7md{;A2%{S["suggested""insisted on""did"]A2/=+" it"+}{"To "["fool""satisfy"_"please"]A(2/:B=" the "["smart""bald""tall""rich""stupid"]B=SM}?[M"Stewie""Peter""Homer""The programmer""The system manager""You"]A=\'!}{["How should I know?""Stop asking!""Don't ask!"]\(=}?
```
[Permalink](http://cjam.aditsu.net/#code=99mrqi_%5D)0%3E%3Di%3AA7md%7B%3BA2%25%7BS%5B%22suggested%22%22insisted%20on%22%22did%22%5DA2%2F%3D%2B%22%20it%22%2B%7D%7B%22To%20%22%5B%22fool%22%22satisfy%22_%22please%22%5DA(2%2F%3AB%3D%22%20the%20%22%5B%22smart%22%22bald%22%22tall%22%22rich%22%22stupid%22%5DB%3DSM%7D%3F%5BM%22Stewie%22%22Peter%22%22Homer%22%22The%20programmer%22%22The%20system%20manager%22%22You%22%5DA%3D%5C'!%7D%7B%5B%22How%20should%20I%20know%3F%22%22Stop%20asking!%22%22Don't%20ask!%22%5D%5C(%3D%7D%3F&input=21)
Haven't used CJam before, so I'll take any tips. I'm sure there's a lot of tricks I don't know!
(I couldn't figure out how to name this as a function called "why" - it appears that functions don't exist in CJam - so I'm not sure if a CJam answer is okay or not...)
[Answer]
# Lua 5.3.0, 452 460 446 bytes
This is my first attempt at a code golf, so please correct me if I did something wrong!
```
a={"Stewie","Peter","Homer","The Programmer","The system manager","You"}b={"fool ","satisfy ",n,"please "}b[3]=b[2]why=function(n)pcall(math.randomseed,n and n>0 and n)n=math.random(1e9)q=n>>4r=n>>8return 1>n&7 and({"How should I Know?","Stop asking!","Don't ask!"})[q%3+1]or 0<n%2 and a[q%6+1]..({" suggested"," insisted on"," did"})[r%3+1].." it"or"To "..b[q%4+1].."the "..({"smart ","bald ","tall ","rich ","stupid "})[r%5+1]..a[(r>>4)%6+1]end
```
Ungolfed: 
```
a={
    "Stewie",
    "Peter",
    "Homer",
    "The Programmer",
    "The system manager",
    "You"
}
b={
    "fool ",
    "satisfy ",
    n,
    "please "
}
b[3]=b[2]
why=function(n)
    pcall(math.randomseed,n and n>0 and n)
    n=math.random(1e9)
    q=n>>4
    r=n>>8
    return
            1>n&7 and
                ({"How should I Know?","Stop asking!","Don't ask!"})[q%3+1]
            or 0<n%2 and
                a[q%6+1]..({" suggested"," insisted on"," did"})[r%3+1].." it"
            or
                "To "..b[q%4+1].."the "..({"smart ","bald ","tall ","rich ","stupid "})[r%5+1]..a[(r>>4)%6+1]
end
```
[Answer]
# Python (2), 692 bytes
I’m still learning, so please be gentle! :)
```
from sys import argv,maxint
import random
def why(*O):
 P=["You","Stewie","Peter","Homer","programmer","system manager"];E=["did","suggested","insisted on","insisted on"];I=["please","fool","satisfy","satisfy"];Q=["stupid","smart","bald","tall","rich"];S=["Don't ask!","How should I know?","Stop asking!"]
 if len(argv)>1:A=O[0]
 else:A=random.randint(-maxint-1,maxint)
 if A%7==0:print S[A%3]
 else:
  M=P[A%6]
  if A%11==0:
   M=P[4]
  if A%2==0:
   if M==P[0]:M="you"
   U=I[(A%8)/2];Z=Q[(A%10)/2];print"To %s the %s %s!"%(U,Z,M)
  if A%2==1:
   if M==P[4]:M="The %s"%P[4]
   if M==P[5]:M="The %s"%P[5]
   C=E[((A+1)/2)%4];print"%s %s it!"%(M,C)
if len(argv)>1:why(int(argv[1]))
else:why()
```
Works with or without an int as a command line argument.
I tried to emphasise code correctness as much as possible, as with generating random numbers from `-sys.maxint - 1` to `sys.maxint` and displaying sentences in the right case.
The code relies very heavily of if-statements that I’m sure could be replaced with something more place efficient.
Feedback is very welcome!
### Ungolfed (1341 bytes)
```
from sys import argv, maxint
import random
def Why(*Optional):
    Persons = ["You", "Stewie", "Peter", "Homer", "programmer", "system manager"]
    Endings = ["did it", "suggested it", "insisted on it", "insisted on it"]
    Verbs = ["please", "fool", "satisfy", "satisfy"]
    Adjectives = ["stupid", "smart", "bald", "tall", "rich"]
    SpecialCases = ["Don't ask!", "How should I know?", "Stop asking!"]
    
    if len(argv) > 1:
        Argument = Optional[0]
    else:
        Argument = random.randint(-maxint - 1, maxint)
        
    if Argument % 7 is 0:
        print SpecialCases[Argument % 3]
    else:
        Person = Persons[(Argument) % 6]
        if Argument % 11 is 0:
            Person = "programmer"
        if Argument % 2 is 0:
            if Person is "You":
                Person = "you"
            Verb = Verbs[(Argument % 8) / 2]
            Adjective = Adjectives[(Argument % 10) / 2]
            print "To %s the %s %s!" % (Verb, Adjective, Person)
        if Argument % 2 is 1:
            if Person is "programmer":
                Person = "The programmer"
            if Person is "system manager":
                Person = "The system manager"
            Ending = Endings[((Argument + 1) / 2) % 4]
            print "%s %s!" % (Person, Ending)
if len(argv) > 1:
    Why(int(argv[1]))
else:
    Why()
```
]