-1

Not randint because it seems that it relies on the previous result to predict the next one I want to be able to generate totally random numbers but still within a certain range

Because here is the problem:

If I put randint(10,14) it will display more than 11 more than the rest, just because it fell on 11 at the beginning (or in my program it did)

If I extend the range to randint(10,30) there will be more than 15,16,17 but much less of the rest or nothing in the 20 or 30 range.

I don't know if you see what I'm talking about, but in my program I get a lot more of some values and others not at all, while they are well and truly in the range.

Veera Nagireddy
  • 1,656
  • 1
  • 3
  • 12
jush456
  • 51
  • 5
  • Even if it's not possible with random module I want to know if there's another alternative – jush456 Aug 30 '22 at 08:36
  • And I haven't used 'seed' – jush456 Aug 30 '22 at 08:39
  • 2
    Dost this answer your question?https://stackoverflow.com/questions/22891583/can-i-generate-authentic-random-number-with-python – HALF9000 Aug 30 '22 at 08:39
  • from your examples it sounds like the results you get follow a gaussian distribution and you are looking for a uniform distribution. From the documentation and the examples here https://stackoverflow.com/questions/12164280/is-pythons-random-randint-statistically-random I would expect `randint` to be uniform so all numbers in your range should appear with the same chance – 53RT Aug 30 '22 at 08:44
  • 1
    @HALF9000 if there is any actual question here, then yes, that answers it. However, it seems likely that OP simply expects random numbers to work in a way that they actually don't (this is [extremely common](https://en.wikipedia.org/wiki/Randomness)). – Karl Knechtel Aug 30 '22 at 08:44
  • @53RT that doesn't match the problem description; a gaussian distribution on 10..30 would favour numbers close to 20, not 15-17. – Karl Knechtel Aug 30 '22 at 08:45
  • This answers it if the randomness is also in a range – jush456 Aug 30 '22 at 08:47
  • 3
    You seem to have a wrong conception of what randomness is. A small sample of random integers, as the ones you generate,.will generally have clusters, values that appears much more often than others, and so on. That's expected. An uniform repartition of values in such small samples would be rather rare. So, enjoy what you got, that's close enough to real randomness that one can't tell it isn't. – Thierry Lathuille Aug 30 '22 at 08:53
  • you are right, it's true that it would have been weird to have a totally equal distribution but is it normal that some values do not appear at all? – jush456 Aug 30 '22 at 09:01

1 Answers1

1

All the random functions in current programming languages are pseudo-random algorithm. You can totally predict the result of it if you know its rules. However, you can try to use random.org API to get a true random number if needed

From their site: "The randomness comes from atmospheric noise, which for many purposes is better than the pseudo-random number algorithms typically used in computer programs"

An Nguyen
  • 288
  • 1
  • 15