Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 26th, 2007, 11:21 AM   #11
uman
Expert Programmer
 
Join Date: Dec 2004
Posts: 794
Rep Power: 4 uman is on a distinguished road
To help Fall Back Son:
#include <dealwithrandomnumbergeneratinghardware.h>
int main(){ int randomyesthisreallyisrandom = getsomerandomnumberfromspecializedhardware(); }
Yea IDK if that is real C (I haven't coded in forever) but you get the idea.
__________________
Few people deserve to be compared to (Rush) Limbaugh, most of them were convicted at the Nuremburg trials.
--WilliamSChips on Slashdot
uman is offline   Reply With Quote
Old Mar 26th, 2007, 7:39 PM   #12
ZenMasterJG
Hobbyist Programmer
 
ZenMasterJG's Avatar
 
Join Date: Nov 2004
Location: Boston, MA
Posts: 148
Rep Power: 4 ZenMasterJG is on a distinguished road
Send a message via AIM to ZenMasterJG
You can also pull true random numbers from random.org's via HTTP, SOAP, or CORBA, if you don't have a hardware random number generator. One of the things on my project list is to make the most useless hardware random number generator ever... using raindrops. No rain, no random bits for you! Luckily I live in Boston where it rains more or less constantly, so that shouldn't be a problem
ZenMasterJG is offline   Reply With Quote
Old Mar 26th, 2007, 8:21 PM   #13
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
It is for this approach that buffers/queues were invented. Unfortunately, the approach tends to fail when one needs it the most.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Mar 27th, 2007, 12:29 AM   #14
Fall Back Son
Hobbyist Programmer
 
Join Date: Oct 2006
Posts: 204
Rep Power: 2 Fall Back Son is on a distinguished road
Quote:
Originally Posted by DaWei View Post
I didn't mention grammar.

The statement was made that C can use processes that generate truly random numbers. No one mentioned that this will happen with any PRNG, regardless of it's distribution.

My view on misinformation remains the same; my expression seemed preferable, at the time of that post, to telling you to just shut the fuck up, read the posts, and maybe resort to Google.
I understand -- I was joking. Sorry for the confusion. And sorry if I'm being a bit thick here, but being truly random just indicates a perfect distribution, as far as randomness goes, over a given set of numbers. Mathematically, that would mean any number in the set is equally likely to be 'chosen' as any other number. Correct?
Fall Back Son is offline   Reply With Quote
Old Mar 27th, 2007, 3:22 AM   #15
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,005
Rep Power: 5 lectricpharaoh will become famous soon enough
Quote:
Originally Posted by Fall Back Son
And sorry if I'm being a bit thick here, but being truly random just indicates a perfect distribution, as far as randomness goes, over a given set of numbers. Mathematically, that would mean any number in the set is equally likely to be 'chosen' as any other number. Correct?
Being truly random means the system is non-deterministic. Any psuedo-random generator, on the other hand, is entirely deterministic. If you know the seed and algorithm, you can determine the next number in the sequence with perfect certainty. This is not the case with truly random numbers.

DaWei's point was that this distinction exists. In many cases, psuedo-random numbers appear sufficiently random to meet the needs of the task at hand, such as in many games, but the distinction is still there. The fact that they are deterministic can be an advantage (in that it allows identical data to be replicated in subsequent tests) or a disadvantage (where this quality can be exploited to predict numbers, which would be bad in, say, an electronic slot machine in a casino).

@OP: Algorithms to generate psuedo-random numbers will use a seed value, and apply a series of operations on it to a) derive a new seed, and b) return a new pseudo-random number. Those that generate truly random numbers typically function by listening for some kind of noise. This noise might be actual sound-type noise, electromagnetic noise, radioactive decay, or whatever. The main requirement is that it fluctuates over time (the faster the better, generally, as it can thus be sampled at a greater speed). By measuring some aspect of said noise (such as amplitude or frequency), and comparing it to some threshold value, a binary one or zero result can be returned. By repeating this process, an arbitrarily long sequence of bits (and thereby bytes) can be assembled that is truly random. Such systems often apply some normalization to ensure there is a roughly uniform distribution; often this is done by adjusting the threshold value. For example, if the average amplitude of the signal over a given time period was x, the threshold could be set at 50% of x in the hopes that a value was equally likely to be either a one or zero. This normalization needs to be done carefully, however, to prevent bias from entering the system. After all, sometimes you really do get ten 'tails' results in a row when flipping a coin.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh is offline   Reply With Quote
Old Mar 27th, 2007, 11:49 PM   #16
Fall Back Son
Hobbyist Programmer
 
Join Date: Oct 2006
Posts: 204
Rep Power: 2 Fall Back Son is on a distinguished road
Thank you.. I appreciate it . Another question (this is a question I found on my "possible midterm questions" study sheet and was unable to answer):

"Write a single C statement that will print a random number from the set 2, 4, 6, 8, 10"

If anyone can give a push in the right direction for that I would appreciate it. I couldn't find anything in my lecture notes for it (which isn't that surprising since the possible midterm questions have been compiled over the years & the lecture notes are kept fairly concise).
Fall Back Son is offline   Reply With Quote
Old Mar 28th, 2007, 1:21 AM   #17
MicDareall
Programmer
 
Join Date: Dec 2005
Posts: 67
Rep Power: 0 MicDareall is an unknown quantity at this point
Quote:
Originally Posted by Fall Back Son View Post
Thank you.. I appreciate it . Another question (this is a question I found on my "possible midterm questions" study sheet and was unable to answer):

"Write a single C statement that will print a random number from the set 2, 4, 6, 8, 10"

If anyone can give a push in the right direction for that I would appreciate it. I couldn't find anything in my lecture notes for it (which isn't that surprising since the possible midterm questions have been compiled over the years & the lecture notes are kept fairly concise).
make an integer array holding those values and use rand() to get a random integer between 0 and length of the array to use as an index in the array.
MicDareall is offline   Reply With Quote
Old Mar 28th, 2007, 2:20 PM   #18
jim mcnamara
Hobbyist Programmer
 
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4 jim mcnamara is on a distinguished road
For randomness good enough for encryption purposes,
consult information about /dev/random in the UNIX operating system.
It is implemented in C
jim mcnamara is offline   Reply With Quote
Old Mar 28th, 2007, 2:32 PM   #19
Fall Back Son
Hobbyist Programmer
 
Join Date: Oct 2006
Posts: 204
Rep Power: 2 Fall Back Son is on a distinguished road
Thanks - don't know why I didn't think of that

but how would it be put into one line of code?

int array[5] = {2, 4, 6, 8, 10} ;
printf("%d", array[rand () % 5]);
Fall Back Son is offline   Reply With Quote
Old Mar 28th, 2007, 2:49 PM   #20
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
printf ("%d", (rand () % 5 + 1) * 2);
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Median/Mode in arrays? {Need help} Java|Tera Java 27 Nov 29th, 2005 10:50 AM
FiveDigit + RandomeNumber Game. TecBrain Java 0 Nov 18th, 2005 2:53 PM
Random Number coldDeath Python 1 Sep 11th, 2005 8:17 AM
Random Number & Average Problem Hadrurus Java 6 Aug 15th, 2005 1:08 PM
non repeating random number generation gencor45 C# 2 Feb 9th, 2005 12:11 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:46 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC