D
Diana
How would I write a program that generates 8 random letters? Thanks!
1. Open up a text editorDiana said:How would I write a program that generates 8 random letters? Thanks!
Diana said:How would I write a program that generates 8 random letters? Thanks!
Diana said:How would I write a program that generates 8 random letters? Thanks!
Diana said:How would I write a program that generates 8 random letters? Thanks!
Diana said:How would I write a program that generates 8 random letters? Thanks!
Bill Pursell said:Here's a start. You'll want to do something with the
generated values, and you'll want to seed the pseudo-random
number generator so you don't get the same sequence each
time. (You did mean pseudo-random, right? If you meant
truly random, well, that's a lot harder.)
#include <stdlib.h>
int
main(void)
{
int i;
for (i=0; i<8; i++)
'a' + rand() % 26;
}
This won;t work on EBCDIC platforms...Bill Pursell said:Here's a start. You'll want to do something with the
generated values, and you'll want to seed the pseudo-random
number generator so you don't get the same sequence each
time. (You did mean pseudo-random, right? If you meant
truly random, well, that's a lot harder.)
#include <stdlib.h>
int
main(void)
{
int i;
for (i=0; i<8; i++)
'a' + rand() % 26;
}
That won't work on turing machine also.David Wade said:This won;t work on EBCDIC platforms...
Tosha said:That won't work on turing machine also.
To those making complaints:
the code does an absolutely perfect job of
giving the OP somewhere to start.
Richard said:Bill Pursell said:
No, it doesn't. It makes a non-portable assumption and gives a poor example
of using rand().
The OP is better served by those who help him or her to start in the right
place.
As opposed to the 5 or 6 posters who ridiculed to OP and provided no
assistance whatsoever.
How is the usage of rand() in the example poor? The usage
there provides a pseudo-random number between 0 and 25
as best as rand() can,
Bill said:As opposed to the 5 or 6 posters who ridiculed to OP and provided no
assistance whatsoever.
How is the usage of rand() in the example poor? The usage
there provides a pseudo-random number between 0 and 25
as best as rand() can, and I avoided seeding it
but did comment that seeding would be necessary in an effort
to avoid completely doing the homework problem for the OP.
I fail to see how my usage is poor.
Forget it, you can't win an argument here, they'll quote the FAQ.
Were you yourself to quote the FAQ, you'll find people claiming
that current C compilers no longer have this problem and that
the FAQ doesn't apply.
Give up.
Bill said:You were right, Richard quoted the FAQ, but he was absolutely
correct to do so. The link he gave was certainly helpful, and
somehow I've never seen it before. I probably skim over it
because I never use rand() and instead use drand48() and
the method described in the last paragraph on the rare occasion
that I need need randomness.
So although the OP apparently abandoned this thread long ago,
and I've become slightly irked at accurate criticism, I still
learned something from it.
Bill Pursell wrote:
Just don't try to repeat what you've learned, otherwise the
other half of the crowd will tell you:
<quote>
But yes, this is exactly what I was telling mensanator: the
fact that his claim about the lower bits having less randomness
is "outdated" given that recent C/C++ libraries do not suffer
from that problem.
</quote>
Forget it, you can't win an argument here ...
John said:This is the price to be paid for getting free help from experts: they
occasionally take themselves a little too seriously.
JS
John Smith said:This is the price to be paid for getting free help from experts: they
occasionally take themselves a little too seriously.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.