PNZ (Guess 3 unique digits in order) From a challenge in a programming book long ago, PNZ is a game where the user must guess three unique digits in the correct order.

Rules:


A random 3 digit number with no repeating digits is generated. (This is what the user is trying to guess)
The user inputs a guess of 3 digits, which is to be evaluated by the program.
Output a "P" for every correct digit in a correct place.
Output a "N" for every correct digit in an incorrect place.
Output a "Z" only if no digits are correct.
Continue accepting inputs until all digits are correct and in the
correct place, then output "PPP" followed by the number of guesses
it took on a new line.


Note:


A "Correct digit" means that one of the digits in the guess is also
one of the digits in the random 3 digit number.
A "Correct place" means it is a "Correct digit" AND is in the same place as the 3 digit random number.
The order of outputting should be all "P"'s first, then "N"'s, or only "Z" if nothing is correct.
If an input contains repeating digits, "P" takes priority over "N" (Example: Number: 123 Input: 111 Output: P)
(OPTIONAL) Inputs that are not exactly 3 digits in length should not be evaluated, nor count towards the running total of guesses


Example if the generated digits were 123

&gt; 147
P
&gt; 152
PN
&gt; 126
PP
&gt; 123
PPP
4


Example if the generated digits were 047

&gt; 123
Z
&gt; 456
N
&gt; 478
NN
&gt; 947
PP
&gt; 047
PPP
5


This is CodeGolf, so the shortest program wins!
JavaScript (ES6) 184 187 195

Edit Saved 8 bytes thx @Neil
Edit Saved 3 bytes thx @user81655

(newlines counted as 1 byte)

d=[...'0123456789']
x=[10,9,8].map(l=&gt;d.splice(Math.random()*l,1))
for(c=p=a='';!p[2];++c)g=prompt(a),n=p='',x.map((d,i)=&gt;d-g[i]?~g.search(d)?n+='N':0:p+='P'),a=p+n||'Z'
alert(a+' '+c)


Test



d=[...'0123456789']
x=[10,9,8].map(l=&gt;d.splice(Math.random()*l,1))
for(c=p=a='';!p[2];++c)
  g=prompt(a),
  n=p='',
  x.map((d,i)=&gt;
        d-g[i]?~g.search(d)?n+='N':0:p+='P'
       ),
  a=p+n||'Z'
alert(a+' '+c)