Random Number

Hi All,
I have a case where I have two 4-digit numbers, one is a random number the bot generates and the other is the user input.
Conditions -

  1. If a digit in the generated random number is right, 1N should be displayed.
  2. If a position in the generated random number is right, 1P should be displayed.

Example: Random number - 4377
User Inputs
7156 > Result: 1N, 0P
7777 > Result: 0N, 2P
3477 > Result: 2N, 2P

Could someone help me with this? Thanks, in advance.

have a look here as it show cases a stack concept helping to implement such things: