Ok so I want to create some code which can generate a random number from a
1. Music file
2. A microphone

PLEASE is their anyway i can do this

Recommended Answers

All 35 Replies

You'll have to use the rand function, look here for some information about it ...

Edit:: A remark on the title of this thread: A computer will never be able to generate real random numbers :)

I never knew music files could generate random numbers :icon_eek:

> I never knew music files could generate random numbers :icon_eek:

> Lol :P, I thought he wanted to generate a random number for the filename of a music file ...

> Anyways: kelechi, could you please reformulate your question in a way we can understand it ?

When Knuth talks about random numbers he mentions a CD of random numbers called "Black and White Noise" which is a mixture of deterministically sampled rap music combined with white noise.

What i mean is to take sound from my microphone and turn it into a number

Well, you may record the sound to a file. Then use some hashing algorithm ( like md5sum) to calculate the hash number of that file.
Each different type of sound will give you different files. And if two files are different, their md5sum hash will of course be different.

Ok so I want to create some code which can generate a random number from a
1. Music file
2. A microphone
PLEASE is their anyway i can do this

It's possible but you need non-trivial theory and lots of experiments. As usually results of these works were a very protected (sometimes patented or/and top secret) know-how(s)...
It's the other story why...
The key point is: what's (and why) a distribution of your home-made generated sequence? If you don't know the answer then it's not a true random number generator...

What i mean is to take sound from my microphone and turn it into a number

A number based on what? Frequency? Decibels? Much more detail is needed.

Frequency based please thanks for all you awnsers so far heres an idea if i retrive sounds from the microphone and then return that value as my number how do i do this

does anyone know how i could do this

>>does anyone know how i could do this
No, not I. But you could try this.

And if two files are different, their md5sum hash will of course be different.

not true. MD5 is broken.

in 2004, Wang et. al. demonstrated that forced MD5 collisions could be generated; in December 2008 the Chaos Communication Group forged an SSL certificate using forced MD5 collisions, in March 2009, Kilma published an algorithm that will force an MD5 collision using a single computer in less than one minute.

>>not true. MD5 is broken.
This is true that MD5 has been broken. I heard this news long before.
I said he could use some hashing algorithm, not necessarily MD5. But the point in giving example as MD5 was that it is very famous.

> MD5 has been broken
>> OK, but it's just really difficult how to do it, a normal PC-user will never manage to break this algorithm, so if your MD5 is just used as a checksum it doesn't really matter whether it can be broken or not :) ...

>>not true. MD5 is broken.

This is true that MD5 has been broken. I heard this news long before.

I'm happy to hear you are so well-informed.

so now there's no reason for you to continue promoting MD5 as an algorithm that produces unique hash values, yes?

OK, but it's just really difficult how to do it, a normal PC-user will never manage to break this algorithm

what a terribly fatal assumption! are you telling me a skript kiddie can't read a published algorithm and implement it on a $200 laptop?

"security through obscurity" is no security at all.


.

so now there's no reason for you to continue promoting MD5 as an algorithm that produces unique hash values, yes?

And what about SHA1 ?

Yes. and No
Yes because it is really broken.
No because it is practically not broken.
I agree with Tux in this regard.
Comparing to the simplicity, the hashing solution will be more practical.
Else, do you have any good solution jephthah?

what a terribly fatal assumption! are you telling me a skript kiddie can't read a published algorithm and implement it on a $200 laptop?
"security through obscurity" is no security at all.
.

> If the hash is just used as a checksum I don't know anybody who would like to put his time and effort in this to (try to) break it :) ...

The OP problem was not specified. I want true random numbers - what did OP mean by that? There are lots of possible answers. May be SHA1 digest of anything is a good solution (of undefined problem;)), it's a question ...

The point is not to use an algoritham to generate random numbers it it to generate TRUE random numbers forinsance the radiation around you is argubly random and the sound waves genereated around you are seemingly random so using sound could i not generate random numbers !

> A computer is only able to generate pseudo-random numbers, if you want real random numbers: just let the user move the mouse across the screen (in a completely random way :))
> From the mouse movement you can generate a (real?) random number

seemingly random

there's your problem: nothing is truly random. some things are just less predictable than others.

the fact is, you're never goign to generate truly random numbers, even if something like that existed. so be happy with the commercially available pseudo-random number generators, like the rest of the world.

if you're doing something that needs more than that, then you're working for the NSA and shouldnt be trolling Daniweb for your answers.

commented: You're absolutely right :) ! +3

An example of this would be to measure the amount of electrical energy in the air at any given point using some sort of analog device, which then converts this into a voltage difference, which is then converted to a digital value (usually between 0 and 4096) to represent the voltage in the air, within a given limit. This value is real world, and while not random, will fluctuate seemingly randomly (if measured in a small enough scale ie micro volts). If used as a seed for a pre-existing random function (like rand() ) this will generate the most random numbers a person can hope to generate via electrons. Using a sound file is overkill in this sense, as the direct input voltage value from the microphone should suffice, and save you a fair bit of math/sonic calculating.

commented: must. resist. stabbing. own. eyes. out. -2
commented: THANKS PERFECT AWNSER +1
commented: Not too bad actually +16

An example of this blah blah blah at any given point using some sort of analog device

or maybe you could sprinkle some magic fairy dust, and use some "sort of analog device" to aggregate the quantum velocities of the fairies at any given point according to Heisenfairy's Uncertainty Principle.

or you could just say fook it, and thow Schroedinger's cat into a lorenz attractor and save yourself a fair bit of math/sonic calculating, and call it 50/50.

:icon_rolleyes:


.

>...then you're working for the NSA...
That's it! (see my the 1st post in the thread above ;).

"Unpredictable" or "non-reproducible" sequences (it's not the same as "random") are used for generating of forgery-resistant keys in cryptography (as usually with special external devices). In actual fact an ordinar desktop computer can generate some kind of (low-quality) "unpredictable" sequences. However it's not so simple work.

I think for non-critical applications (like OP;)) no need in methods like soundtrecks and other exotics. Get keystrokes trace (with millisecond oprecision intervals), calc SHA1 digest of this trace - that's 160 "unpredictable" bytes. Take into account that OP did not define any "randomness" criteria so any one solution is not worse that any others ;)...

Let me repeat myself: more advanced methods are a valued know-how and Daniweb is not the best place to discuss them ;)...

commented: The best method I've seen in this thread :) ! Very very good :P !!! +3

An example of this would be to measure the amount of electrical energy in the air at any given point using some sort of analog device, which then converts this into a voltage difference, which is then converted to a digital value (usually between 0 and 4096) to represent the voltage in the air, within a given limit. This value is real world, and while not random, will fluctuate seemingly randomly (if measured in a small enough scale ie micro volts). If used as a seed for a pre-existing random function (like rand() ) this will generate the most random numbers a person can hope to generate via electrons. Using a sound file is overkill in this sense, as the direct input voltage value from the microphone should suffice, and save you a fair bit of math/sonic calculating.

See this is the awnser I was looking for THANK YOU +rep but how do i do this ?

or maybe you could sprinkle some magic fairy dust, and use some "sort of analog device" to aggregate the quantum velocities of the fairies at any given point according to Heisenfairy's Uncertainty Principle.

or you could just say fook it, and thow Schroedinger's cat into a lorenz attractor and save yourself a fair bit of math/sonic calculating, and call it 50/50.

:icon_rolleyes:


.

Dude that wasn't nice or fair sure you outrank me but that was bang out of order this is why these communitys are set up to try and get away from the ridicule of the "populer" comunity sure im 13 but i want to learn I actuly understood that and its a brillient methord please don't flame a good awnser or daniweb the most "friendly" comunity becomes daniweb the most friendly comunity if you do what jephthah thinks is good

or maybe you could sprinkle some magic fairy dust, and use some "sort of analog device" to aggregate the quantum velocities of the fairies at any given point according to Heisenfairy's Uncertainty Principle.

or you could just say fook it, and thow Schroedinger's cat into a lorenz attractor and save yourself a fair bit of math/sonic calculating, and call it 50/50.

:icon_rolleyes:


.

Umm...What point was made, exactly, with that post?

and kelechi96,
don't get discouraged too much, some of the people around here can be a little ignorant at times, but will usually help you out if you are willing to tolerate it.

>>An example of this would be to measure the amount of electrical energy in
>>the air at any given point using some sort of analog device, which then
>>converts this into a voltage difference, which is then converted to a digital
>>value (usually between 0 and 4096) to represent the voltage in the air, within
>> a given limit.
Thanks for enlighting our minds. But could do tell how will you implement this 'magical' apparatus.

>>See this is the awnser I was looking for THANK YOU +rep but how do i do this ?
Wow, were you?
Ask him. I am no magician.
I doubt if you need that extreme randomness.

>>Umm...What point was made, exactly, with that post?
The same point which you made by yours. He just increased the randomness by a million times.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.