Velocity Reviews > time()

# time()

Bartc
Guest
Posts: n/a

 04-28-2008

"Keith Thompson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Bill Cunningham" <(E-Mail Removed)> writes:
>> [snip]
>> Say you have two dice of six sides. Can you use rand() to create 12
>> options by rolling the die. Now there's another way you can do this
>> simply
>> but using arrays but I do not know how. Something like this.
>>
>> int a [12];
>>
>> Ok there's 12 objects or
>>
>> int a [20];
>>
>> like I want. I can use for to loop over them but I can't get randomness.
>> That's a feature I do not know how to reproduce. It will have to someway
>> depend on the system and most use the system time.

>
> You're still not making sense.
>
> If I roll two six-sided dice, there are 36 (6*6) possible outcomes,
> not 12. I suppose you could divide these up into 12 sets of 3
> outcomes each, but I suspect that's not what you had in mind.

I make it only 11 outcomes (1+1 to 6+6). Although if you listed all
combinations there would be 36.

If certain combinations are important, then you can list the 6 outcomes for
each die separately, totalling 12 outcomes.

--
Bartc

Bill Cunningham
Guest
Posts: n/a

 04-28-2008

"pete" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) m...
>
> /* BEGIN dice.c */
>
> #include <stdio.h>
> #include <stdlib.h>
>
> #define THROWS 1000
> #define str(s) # s
> #define xstr(s) str(s)
>
> int main(void)
> {
> int sum[13] = {0};
> unsigned count = THROWS;
>
> while (count-- != 0) {
> ++sum[rand() % 6 + 1 + rand() % 6 + 1];
> }
> puts("Dice totals from "xstr(THROWS)" throws of a pair of dice:");
> puts("value count");
> for (count = 0; count != sizeof sum / sizeof *sum; ++count) {
> printf("%2u %2d\n", count, sum[count]);
> }
> return 0;
> }
>
> /* END dice.c */
>

Thanks Pete but I can't read some of the program. What does int sum
[13]={0}; mean? Why is there a zero in parenthesis? Also
#define str(s) # s
> #define xstr(s) str(s)

What does that code do?

The rest I can pretty much make out. But what does the % after rand mean?

This is how to learn C.

Bill

Keith Thompson
Guest
Posts: n/a

 04-28-2008
"Bill Cunningham" <(E-Mail Removed)> writes:
> "Keith Thompson" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> (I do not give permission to quote this article, or any other article
>> I post to Usenet, without attribution.)
>>

> What do you mean by this Keith? Do you not want to be quoted in clc's

No, I do not want to be quoted *without attribution*.

Gordon Burditt deliberately deletes attribution lines from quoted
material when he posts followups. The above was directed primarily at
him. He's welcome to quote me (as is anyone else), but not without
giving me credit for my words.

--
Keith Thompson (The_Other_Keith) <(E-Mail Removed)>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Lew Pitcher
Guest
Posts: n/a

 04-28-2008
In comp.lang.c, Bill Cunningham wrote:

>
> "pete" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) m...
>>
>> /* BEGIN dice.c */
>>
>> #include <stdio.h>
>> #include <stdlib.h>
>>
>> #define THROWS 1000
>> #define str(s) # s
>> #define xstr(s) str(s)
>>
>> int main(void)
>> {
>> int sum[13] = {0};
>> unsigned count = THROWS;
>>
>> while (count-- != 0) {
>> ++sum[rand() % 6 + 1 + rand() % 6 + 1];
>> }
>> puts("Dice totals from "xstr(THROWS)" throws of a pair of dice:");
>> puts("value count");
>> for (count = 0; count != sizeof sum / sizeof *sum; ++count) {
>> printf("%2u %2d\n", count, sum[count]);
>> }
>> return 0;
>> }
>>
>> /* END dice.c */
>>

>
> Thanks Pete but I can't read some of the program. What does int sum
> [13]={0}; mean? Why is there a zero in parenthesis?

int sum[13] = {0};

declares sum to be an array of 13 integers, and initializes all elements of
the array to zero. The
{0}
is short form for
{0,0,0,0,0,0,0,0,0,0,0,0,0}

> Also
> #define str(s) # s
>> #define xstr(s) str(s)

>
> What does that code do?

The first #define defines a macro that expands into the macro argument
preceded by the "stringize" macro operator. The second #define defines a
macro that uses the first macro to change it's argument into a string.

Together, they make it such that, with
#define THROWS 1000
the macro invocation
xstr(THROWS)
expands to
str(1000)
which expands to
# 1000
which "stringizes" into the C string
"1000"

> The rest I can pretty much make out. But what does the % after rand mean?

That's the C "modulo" operator. It provides the remainder of an integer
division. 3 / 2 == 1
3 % 2 == 1 == (3 - ((3/2)*2))

> This is how to learn C.

--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------

Keith Thompson
Guest
Posts: n/a

 04-28-2008
"Bartc" <(E-Mail Removed)> writes:
> "Keith Thompson" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> "Bill Cunningham" <(E-Mail Removed)> writes:
>>> [snip]
>>> Say you have two dice of six sides. Can you use rand() to create 12
>>> options by rolling the die. Now there's another way you can do this
>>> simply
>>> but using arrays but I do not know how. Something like this.
>>>
>>> int a [12];
>>>
>>> Ok there's 12 objects or
>>>
>>> int a [20];
>>>
>>> like I want. I can use for to loop over them but I can't get randomness.
>>> That's a feature I do not know how to reproduce. It will have to someway
>>> depend on the system and most use the system time.

>>
>> You're still not making sense.
>>
>> If I roll two six-sided dice, there are 36 (6*6) possible outcomes,
>> not 12. I suppose you could divide these up into 12 sets of 3
>> outcomes each, but I suspect that's not what you had in mind.

>
> I make it only 11 outcomes (1+1 to 6+6). Although if you listed all
> combinations there would be 36.

Exactly. 1+6 is distinct from 2+5, for example.

> If certain combinations are important, then you can list the 6 outcomes for
> each die separately, totalling 12 outcomes.

Only if you first randomly choose one of the two dice to throw by
itself.

--
Keith Thompson (The_Other_Keith) <(E-Mail Removed)>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Keith Thompson
Guest
Posts: n/a

 04-28-2008
pete <(E-Mail Removed)> writes:
> Keith Thompson wrote:
>> "Bartc" <(E-Mail Removed)> writes:
>>> "Keith Thompson" <(E-Mail Removed)> wrote in message
>>> news:(E-Mail Removed)...
>>>> "Bill Cunningham" <(E-Mail Removed)> writes:
>>>>> [snip]
>>>>> Say you have two dice of six sides. Can you use rand() to create 12
>>>>> options by rolling the die. Now there's another way you can do
>>>>> this simply
>>>>> but using arrays but I do not know how. Something like this.
>>>>>
>>>>> int a [12];
>>>>>
>>>>> Ok there's 12 objects or
>>>>>
>>>>> int a [20];
>>>>>
>>>>> like I want. I can use for to loop over them but I can't get randomness.
>>>>> That's a feature I do not know how to reproduce. It will have to someway
>>>>> depend on the system and most use the system time.
>>>> You're still not making sense.
>>>>
>>>> If I roll two six-sided dice, there are 36 (6*6) possible outcomes,
>>>> not 12. I suppose you could divide these up into 12 sets of 3
>>>> outcomes each, but I suspect that's not what you had in mind.
>>> I make it only 11 outcomes (1+1 to 6+6). Although if you listed all
>>> combinations there would be 36.

>>
>> Exactly. 1+6 is distinct from 2+5, for example.

>
> But more controversially, 1+6 is distinct from 6+1,
> if you think that there are 36 (6*6) possible outcomes.

There are 36 equally probable outcomes. Use differently colored dice
to make this clearer.

But the point is that the OP was talking about 12 outcomes, which
doesn't make any sense unless he wants to divide the 36 outcomes into
12 sets of 3 each. I seriously doubt that that's what he had in mind,
though; he probably was thinking that 6 outcomes for one die plus 6
for the other equals 12 possible outcomes.

--
Keith Thompson (The_Other_Keith) <(E-Mail Removed)>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Bartc
Guest
Posts: n/a

 04-28-2008

"Keith Thompson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Bartc" <(E-Mail Removed)> writes:
>> "Keith Thompson" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> "Bill Cunningham" <(E-Mail Removed)> writes:
>>>> [snip]
>>>> Say you have two dice of six sides. Can you use rand() to create 12
>>>> options by rolling the die. Now there's another way you can do this
>>>> simply
>>>> but using arrays but I do not know how. Something like this.
>>>>
>>>> int a [12];
>>>>
>>>> Ok there's 12 objects or
>>>>
>>>> int a [20];
>>>>
>>>> like I want. I can use for to loop over them but I can't get
>>>> randomness.
>>>> That's a feature I do not know how to reproduce. It will have to
>>>> someway
>>>> depend on the system and most use the system time.
>>>
>>> You're still not making sense.
>>>
>>> If I roll two six-sided dice, there are 36 (6*6) possible outcomes,
>>> not 12. I suppose you could divide these up into 12 sets of 3
>>> outcomes each, but I suspect that's not what you had in mind.

>>
>> I make it only 11 outcomes (1+1 to 6+6). Although if you listed all
>> combinations there would be 36.

>
> Exactly. 1+6 is distinct from 2+5, for example.
>
>> If certain combinations are important, then you can list the 6 outcomes
>> for
>> each die separately, totalling 12 outcomes.

>
> Only if you first randomly choose one of the two dice to throw by
> itself.

They're identical. It doesn't matter which one is thrown first. Just program
the machine 'not to look' until the second one is thrown.

Anyway it's not clear why arrays are needed. Each double throw can be
represented by a single char value.

--
Bartc

Joachim Schmitz
Guest
Posts: n/a

 04-28-2008
Gordon Burditt wrote:
>> Say you have two dice of six sides. Can you use rand() to create
>> 12 options by rolling the die.

>
> Note that rolling two dice of six sides each (adding the results)
> and rolling one die of 12 sides does NOT generate the same probability
> distribution.

Esp. the probabily of a 1 is 0 with 2 dice.

Bye, Jojo

Joachim Schmitz
Guest
Posts: n/a

 04-28-2008
Bill Cunningham wrote:
> "Keith Thompson" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>> should have provided an attribution line, something like
>>
>> Keith Thompson <(E-Mail Removed)> writes:
>>
>> Please leave that line in place. Quoting somebody without
>> attribution is considered rude. (I think I've told you this before.)

>
> Now is this how it should be. I'm using outlook express It

Me too, and I never had that issue.

> took me awhile way way back to learn not to top post. Sorry I will
> work on this. I have to do it all manually.

Have a look at OE-QuoteFix. It solves several weaknesses of OE

Bye, Jojo