How to select certain rows from an array generated by a multinomial distribution with 'n' degrees?

I came across this concept of “multinomial distribution” in my stats class but I didn’t know this can also be implemented using code in Python. I was going through an online course regarding Data Science and saw this code:

I don't know how this code works, what I do know is it implements the concept of multinomial distribution by selecting certain rows from a dataset/array. Can anyone explain to me how this code works? Or how this phenomenon fits into Python using any other simplified and efficient code snippet?