Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

randoms

0 views
Skip to first unread message

Bill Cunningham

unread,
Nov 6, 2009, 8:30:57 PM11/6/09
to
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


Keith Thompson

unread,
Nov 6, 2009, 8:58:17 PM11/6/09
to

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"

Curtis Dyer

unread,
Nov 6, 2009, 10:01:25 PM11/6/09
to

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

Richard

unread,
Nov 7, 2009, 11:50:22 AM11/7/09
to
"Bill Cunningham" <bil...@suddenlink.net> writes:

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

Richard

unread,
Nov 7, 2009, 11:53:41 AM11/7/09
to
Curtis Dyer <dye...@gmail.com> writes:

> 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.

Seebs

unread,
Nov 7, 2009, 1:24:59 PM11/7/09
to
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.
--
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!

Bill Cunningham

unread,
Nov 7, 2009, 1:39:27 PM11/7/09
to

"Keith Thompson" <ks...@mib.org> wrote in message
news:ln8wejr...@nuthaus.mib.org...

> comp.lang.c FAQ, question 13.16.

Thanks. I will try this and see if it works.

Bill


Richard Heathfield

unread,
Nov 7, 2009, 1:49:51 PM11/7/09
to
In <4af5bed1$0$5352$bbae...@news.suddenlink.net>, Bill Cunningham
wrote:

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

Richard

unread,
Nov 7, 2009, 2:10:37 PM11/7/09
to
Seebs <usenet...@seebs.net> writes:

> 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.

Gordon Burditt

unread,
Nov 7, 2009, 11:07:57 PM11/7/09
to
>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.

If the program doesn't have to be correct, it can run in 0 bytes for 0 time.

Kenny McCormack

unread,
Nov 9, 2009, 6:50:51 AM11/9/09
to
In article <Gu-dnSNkie6A2WvX...@posted.internetamerica>,

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.

0 new messages