0

I am trying to implement a simple pseudo random generator used in cryptography called LFSR (linear feedback shift register).

I have checked a few JS and Python websites for a way to generate a True Random Number but all I find is pseudo random number generator.

Is it possible to get a TRN from these coding languages ?

Just some pointers would be fine, I am not originally a coder so got a bit confused by this.

Mah Neh
  • 84
  • 6
  • 1
    There is [cryptographic safe randomness](https://stackoverflow.com/questions/4083204/secure-random-numbers-in-javascript) – trincot Aug 03 '22 at 10:34
  • 1
    Does this answer your question? [Generate true random numbers in python](https://stackoverflow.com/questions/63746362/generate-true-random-numbers-in-python) – Peter O. Aug 03 '22 at 10:52
  • 1
    See also my answer there: https://stackoverflow.com/questions/63746362/generate-true-random-numbers-in-python/63746585#63746585 – Peter O. Aug 03 '22 at 10:53
  • Thanks. I am interested in JS as well. – Mah Neh Aug 04 '22 at 22:18

2 Answers2

2

True randomness comes from stuff like detecting radioactive decay events. So no, you cannot achieve true randomness with standard hardware.

Pajunen
  • 116
  • 1
  • 2
  • I dont think anyone can predict the electronic-circuit state of a laptop, so I wonder if fluctuations in the current or the circuit could be used. – Mah Neh Aug 03 '22 at 10:30
  • Could intel [intrinsics](https://stackoverflow.com/questions/31214457/how-to-use-rdrand-intrinsics) be of any use to you? – Pajunen Aug 03 '22 at 10:36
  • Python [secrets module](https://docs.python.org/3/library/secrets.html) ? – Pajunen Aug 03 '22 at 10:50
1

On your own, achieving true randomness is very difficult, but some APIs that do this exist.

random.org does it, for example.

  • Thanks but why? Please see comment to the prev answer. – Mah Neh Aug 03 '22 at 10:33
  • There are plenty of accessible chaotic events that could be harnessed in order to generate a random seed (wind, environmental sounds, maybe the electronic-circuit state you talked about...?), but the difficulty resides in using them in a meaningful way without appropriate sensing equipment and without being able to influence the results by provoking those kinds of events near the sensors. – Quentin Portet Aug 03 '22 at 10:46
  • 1
    @QuentinPortet Having a random seed doesn't make a PRNG "truly random". The seed just sets the initial state of a PRNG. Given enough observations, the state can be inferred and subsequent values can be predicted with certainty. – pjs Aug 04 '22 at 15:47
  • @pjs I hadn't thought of that! It makes sense, thank you! – Quentin Portet Aug 08 '22 at 14:13