0

How to write python with:

Generate 5 random numbers with a certain probability from number 1-25(no repeat)

Like generate 1 has 5%, 2 has 7% something like that

azro
  • 53,056
  • 7
  • 34
  • 70
  • This answer might be a good place to look at. > https://stackoverflow.com/questions/4265988/generate-random-numbers-with-a-given-numerical-distribution – Anurag A S Dec 22 '19 at 09:01
  • 3
    Does this answer your question? [Generate random numbers with a given (numerical) distribution](https://stackoverflow.com/questions/4265988/generate-random-numbers-with-a-given-numerical-distribution) – David Dec 22 '19 at 09:02
  • Create a list with 5x1, 7x2...and pick one item randomly. – Klaus D. Dec 22 '19 at 09:02
  • Note that the 'no repeat' part of the criterion means you'll need to 'remove' selected values from the list of possible values. If you had 100 entries in your array, 7 of them for value 2, and then value 2 is selected, you'll need to zap those 7 entries and reduce the range from 100 to 93 to pick other values with the appropriate probability. I'm not sure that the 'no repeat' criterion makes much sense with weighted probabilities — I suspect that you lose some of the guarantees of the correct distribution. Be cautious. – Jonathan Leffler Dec 22 '19 at 09:07

0 Answers0