#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
srand(time(NULL));
printf("%i\n", rand());
}
This is great at getting seemingly real random numbers but they're huge
numbers. Can use this randomness to get a number from 1-12? 1-16 and so on?
Bill
comp.lang.c FAQ, question 13.16.
--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Take a look at Q13.16 in the C FAQ <http://www.c-faq.com>.
--
Don't worry about efficiency until you've attained correctness.
~ Eric Sosman
It is impossible to do this in C as you have discovered with your
extensive research Bill. I suggest that for complex mathematical
problems like this that you look into using Haskell. It's really
easy. Honest.
--
"Avoid hyperbole at all costs, its the most destructive argument on
the planet" - Mark McIntyre in comp.lang.c
> On 06 Nov 2009, "Bill Cunningham" <bil...@suddenlink.net> wrote:
>
>> I have this short program. And I think I've asked something
>> similar
>> before but I want random up to 12 numbers here representing a
>> dice.
>>
>> #include <stdio.h>
>> #include <stdlib.h>
>> #include <time.h>
>>
>> int main(void)
>> {
>> srand(time(NULL));
>> printf("%i\n", rand());
>> }
>>
>> This is great at getting seemingly real random numbers but
>> they're huge
>> numbers. Can use this randomness to get a number from 1-12? 1-16
>> and so on?
>>
>> Bill
>
> Take a look at Q13.16 in the C FAQ <http://www.c-faq.com>.
,----
| --
| Don't worry about efficiency until you've attained correctness.
| ~ Eric Sosman
`----
Singularly some of the worst advice ever for proficient C programmers.
There is no point in attaining "correctness" in a dog of a program which
needs to be totally replumbed to achieve the desired level of
efficiency.
ALWAYS look at overall data flow and data structure design with an aim to
achieving reasonable efficiency at an EARLY stage in system development.
And you bitch about other people giving people bad answers or
being dismissive of them?
-s
p.s.: To be fair, either Bill is a stellar troll or there really isn't
much point, but it still seems a bit silly to do this and complain that
other people do it.
--
Copyright 2009, all wrongs reversed. Peter Seebach / usenet...@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
> comp.lang.c FAQ, question 13.16.
Thanks. I will try this and see if it works.
Bill
It works if you do it right.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
"Usenet is a strange place" - dmr 29 July 1999
Sig line vacant - apply within
> On 2009-11-07, Richard <rgr...@gmail.com> wrote:
>> It is impossible to do this in C as you have discovered with your
>> extensive research Bill. I suggest that for complex mathematical
>> problems like this that you look into using Haskell. It's really
>> easy. Honest.
>
> And you bitch about other people giving people bad answers or
> being dismissive of them?
>
> -s
> p.s.: To be fair, either Bill is a stellar troll or there really isn't
> much point, but it still seems a bit silly to do this and complain that
> other people do it.
If you don't see the difference between my reply and Streater's "as I
recall" where he was actively "helping" but being totally wrong then
you're a bigger fool than I first thought.
Bill is a stellar troll. And if he's not then having a bit of fun is no
harm either since it goes in one ear and out the next.
If the program doesn't have to be correct, it can run in 0 bytes for 0 time.
There is a difference - a big huge, honking difference - between being
correct (without the quotes) and posessing "correctness" (in the CLC
sense, and with the quotes).
In CLC, "correctness" is analogous to "truthiness". Note that many of
the CLC stalwarts are crypto-Bushies.