How to generate random numbers with a .wav file?

5

1

I want to generate random numbers within a certain range (1 to 26) using a .wav file with only static noise.

The results need to be repeatable.

Is there any service/program/method of accomplishing this in Windows 7?

zeldarulez

Posted 2012-07-31T21:25:25.860

Reputation: 632

1What do you want to do with the random numbers? The answer to this question affects which method will be best to do this. – jmetz – 2012-08-01T14:29:25.867

First of all, do you know any programming languages? I assume not but that doesn't change the fact that random generated numbers that are repeatable are not random at all. That said, you may consider hashing the file with MD5 and use the hash as a seed. That will guarantee that the seed is unique to that sound snipped can reproduce predictable sequence of numbers. However, this is NOT random. – anber – 2014-02-07T05:54:12.147

@anber Yes, I have experience from a couple programming languages. From what you wrote, I will keep that in mind. Thanks! ;) – zeldarulez – 2014-02-08T05:34:07.660

Answers

6

Try Python's scipy module,

import scipy.io.wavfile as sio

data = sio.read(FILENAME)
data = data[1].astype('float')
data -= data.min()
data *= 25.0*data.max()
data += 1

The data is now a vector and can be saved or used for further processing etc.

If, for example, you just want to save the output as a csv (comma separated values) file, you could then use

import csv
fout = open('output.csv', 'w')
wrt = csv.writer(fout)
wrt.writerow(data)
fout.close()

jmetz

Posted 2012-07-31T21:25:25.860

Reputation: 832

i unfortunatly dont program/know python. How could i use this snippit of code? – zeldarulez – 2012-07-31T23:01:11.590

3@zeldarulez: As long as you can think logically, Python is one of the easiest programming languages to learn. – Ignacio Vazquez-Abrams – 2012-07-31T23:11:48.970

@zeldarulez - what do you want to do with the random numbers? – jmetz – 2012-08-01T14:12:12.580

i would like to use the use the random numbers to create a one-time pad key. I know about random.org, but i want to use a method to create it myself

– zeldarulez – 2012-08-01T16:33:06.857

@IgnacioVazquez-Abrams learning a new language will be ok ;) – zeldarulez – 2012-08-01T16:39:07.100

0

I have created true random number file using AM radio waves or what is popularly called white noise. I've done it in Linux, so if you want that, follow these steps.

  1. Use your radio that has AM.
  2. Put frequency somewhere between radio channels - you should get white noise from radio waves and other magnetic interference.
  3. Use Linux distro (Debian/RedHat based) - I have used Ubuntu.
  4. Install "sox" (bundle) application, which has a small app called "rec" that you will use.
  5. After you installed sox, place your microphone to the speakers so they can record "white noise" and use this command:

    rec -c 1 -r 8000 -t wav -e signed-integer randomWAVfile
    

In short:

  • -c 1 (you are using one channel)
  • -r 8000 (sampling of 8000 Hz)
  • -t wav (format file as wav)
  • -e signed-integer (and reads 16 bit at the same time)
  • randomWAVfile (file name - by your personal preference)

You will have a file with random noise that is "formated" as wav file (it holds wav header of 14bits - if I am not mistaken).

To strip down the header and "remove" potential duplicates, use this program written in C by Rick Van Reinn.

It is not a big issue, but be aware that castings in this program is not correct and your gcc will start to complain.

Source code link: Openfortress source code

By pushing down the file through the program:

cat randomWAVfile | ./noise-filter > randomBits

you will get the TRNG file.

I have learned that by using this link. The only thing the guy who created the original tutorial were using ancient versions of Linux that operated with OSS (open sound sys) and not alsa.

Original post: Openfortress original link

dovla091

Posted 2012-07-31T21:25:25.860

Reputation: 101

Please read the question again carefully. Your answer does not answer the original question. OP said "The results need to be repeatable." – DavidPostill – 2016-02-22T23:05:00.073

Sorry David, I was browsing something and haven't red question carefully. My apology. – dovla091 – 2016-02-23T16:46:37.243

0

If the file is PCM-encoded then you can use Python's wave module to read the samples in the file, and then fold the values into the range.

Ignacio Vazquez-Abrams

Posted 2012-07-31T21:25:25.860

Reputation: 100 516

4The wave module reads the data as a string - I would recommend using scipy.io.wavfile instead as I posted in my answer - it makes the data much more manageable for the subsequent rescaling. – jmetz – 2012-07-31T21:41:59.727