0

Everything I find says to use the Random module, but I want to do it from scratch. How would I do that?

I've done some work with messing with the Time module, and muddling the numbers to try to get a random(ish) result. (Returns a Boolean depending on if the rounded final result is divisible by two.)

My original function seems to fluctuate quite a bit. Yesterday it was around a 50/50 split, but now it's only about 10/90.

I'm trying to get it stable, but now it is always returning True 100% of the time...

Elliot
  • 11
  • 2
  • You need a PRNG that has a seed value to reproduce the results and a range parameter to restrict the outputs. There are no true random generators except quantum field plugged ones. PRNGs are made to debug and yes, you will get somethings like 20/80 splits as well. Try using linear congruential generator for a feel. – LazyCoder Jul 26 '19 at 23:55
  • 2
    Your question is really what kind of algorithm makes a mathematically good PRNG. There's a worthy discussion that can be found on sister site MathOverflow: https://mathoverflow.net/questions/29494/pseudo-random-number-generation-algorithms – codingatty Jul 26 '19 at 23:58
  • 2
    A question without any code isn't really a good fit for Stack Overflow -- there are other Stack Exchange sites for questions about math/statistics/etc; but this one is strictly for narrow questions about coding. (If your problem is more about coming up with a good algorithm than implementing that algorithm, then, it's probably a fit for a different SE site). – Charles Duffy Jul 27 '19 at 00:14
  • For starters have a look at a [Linear congruential generator](https://en.wikipedia.org/wiki/Linear_congruential_generator). When you have that working, you can try more complex PRNGs like the Mersenne Twister. – rossum Jul 27 '19 at 10:10
  • Check LCG implementation [here](https://stackoverflow.com/questions/56983355/portability-and-reproducibility-of-rng-techniques/56998216#56998216) – Severin Pappadeux Jul 27 '19 at 14:35
  • Never, ever, "roll your own" random number generation or encryption unless you have a degree in math and relevant experience. LCG's are terrible by themselves, but can be made part of a good algorithm if you know what you're doing (and trust me, you don't). If you need a simple but reasonably good algorithm to experiment with, I suggest Marsaglia's xor-shift. – Lee Daniel Crocker Jul 28 '19 at 17:45

0 Answers0