Go Back   Velocity Reviews > Newsgroups > C Programming
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

C Programming - randoms

 
Thread Tools Search this Thread
Old 11-07-2009, 01:30 AM   #1
Default randoms


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




Bill Cunningham
  Reply With Quote
Old 11-07-2009, 01:58 AM   #2
Keith Thompson
 
Posts: n/a
Default Re: randoms
"Bill Cunningham" <> writes:
> 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?


comp.lang.c FAQ, question 13.16.

--
Keith Thompson (The_Other_Keith) kst- <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"


Keith Thompson
  Reply With Quote
Old 11-07-2009, 03:01 AM   #3
Curtis Dyer
 
Posts: n/a
Default Re: randoms
On 06 Nov 2009, "Bill Cunningham" <> 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


Curtis Dyer
  Reply With Quote
Old 11-07-2009, 06:24 PM   #4
Seebs
 
Posts: n/a
Default Re: randoms
On 2009-11-07, Richard <rgrdev_@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-
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!


Seebs
  Reply With Quote
Old 11-07-2009, 06:39 PM   #5
Bill Cunningham
 
Posts: n/a
Default Re: randoms

"Keith Thompson" <kst-> wrote in message
news:...

> comp.lang.c FAQ, question 13.16.


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

Bill




Bill Cunningham
  Reply With Quote
Old 11-09-2009, 11:50 AM   #6
Kenny McCormack
 
Posts: n/a
Default Re: randoms
In article <Gu- ca>,
Gordon Burditt <> wrote:
>>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.
>


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.



Kenny McCormack
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46