Function for calculating dice odds when rolling multiple die

I’m working on a way to display dice statistics like you can see at the site https://anydice.com/ , I’ve spent a bit looking through the source code but it’s pretty thick alltogether so i decided to ask here. Basically, all i need help with is making a function that:

  • Lets you pick a dice with a certain amount sides, for example: 6.
  • Lets you pick how many times you want to roll this dice.
  • Returns the percentages of rolling each possible number with said dice.

I know the question might be a bit shitty, but this is kind of my last resort.

So far, I’ve tried finding the functions and stumbled upon this medium blog however I was wondering if it could maybe be done with percentages.