473,387 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Generate two random number and multiply

I'm new so i apologize if this is in the wrong spot. I'm also new to
programming in C and i've been searching for quite a while on how to
create a program using C that will generate two random numbers,
multiply them, and ask you for the result. It also needs to have four
responses for both right and wrong answers and should print them
randomly as well. The program should use at least 2 functions. Any
help would be greatly appreciated.

Thanks

Mar 5 '07 #1
20 7784
jj**********@hotmail.com wrote:
I'm new so i apologize if this is in the wrong spot. I'm also new to
programming in C and i've been searching for quite a while on how to
create a program using C that will generate two random numbers,
multiply them, and ask you for the result. It also needs to have four
responses for both right and wrong answers and should print them
randomly as well. The program should use at least 2 functions. Any
help would be greatly appreciated.

Thanks
This seems like a homework question. Have you atleast made an attempt.
Attempt a try at the problem and post the code here, however bad it
is.

Hint: To generate pseudo-random integer values, use the rand function.
Before using it, it's recommended to invoke the srand function to
"seed" the pseudo-random number generator. To learn how to use rand
and srand, try looking at your implementation's documentation for the
Standard library. If it's a Unix system, try typing 'man 3 rand' and
'man 3 srand' at the command prompt.

To select a string, from a collection randomly, you can use the same
rand function to get a random number, trim it down to be within the
bounds of your array of strings and use it to index into the array and
extract a random string.

Well, try your hand at it.

Mar 5 '07 #2
At about the time of 3/5/2007 7:23 AM, jj**********@hotmail.com stated
the following:
I'm new so i apologize if this is in the wrong spot. I'm also new to
programming in C and i've been searching for quite a while on how to
create a program using C that will generate two random numbers,
multiply them, and ask you for the result. It also needs to have four
responses for both right and wrong answers and should print them
randomly as well. The program should use at least 2 functions. Any
help would be greatly appreciated.

Thanks
Homework?

Go take a look and rand(3) and srand(3). It's standard C.

http://www.acm.uiuc.edu/webmonkeys/book/c_guide/

--
Daniel Rudy

Email address has been base64 encoded to reduce spam
Decode email address using b64decode or uudecode -m

Why geeks like computers: look chat date touch grep make unzip
strip view finger mount fcsk more fcsk yes spray umount sleep
Mar 5 '07 #3

<jj**********@hotmail.comwrote in message
I'm new so i apologize if this is in the wrong spot. I'm also new to
programming in C and i've been searching for quite a while on how to
create a program using C that will generate two random numbers,
multiply them, and ask you for the result. It also needs to have four
responses for both right and wrong answers and should print them
randomly as well. The program should use at least 2 functions. Any
help would be greatly appreciated.
rand() will generate a random number between 0 and RAND_MAX.
RAND_MAX is usually 32767, which is too high for arithmetic drill.

So get a random number in the range 1 = 100 by taking modulus 100. There are
more accurate ways of doing this, but this should be fine now.

Unfortunately you program will generate exactly the same numbers on each
run. So call srand() with the time from time() to seed the random number
generator.

Having got your random numbers, print them out with a message asking the
user to multiply. Then call scanf() to input the result. Don't forget to
check the return value of scanf() to make sure the user actually entered a
number.

Now you need to check whether the number is correct. If it is, call the
random number generator again and print out a random "well done" message -
you can use a switch - if not, print out a "wrong answer message".
--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Mar 5 '07 #4
rand() will generate arandomnumber between 0 and RAND_MAX.
RAND_MAX is usually 32767, which is too high for arithmetic drill.

So get arandomnumber in the range 1 = 100 by taking modulus 100. There are
more accurate ways of doing this, but this should be fine now.

Unfortunately you program will generate exactly the same numbers on each
run. So call srand() with the time from time() to seed therandomnumber
generator.

Having got yourrandomnumbers, print them out with a message asking the
user tomultiply. Then call scanf() to input the result. Don't forget to
check the return value of scanf() to make sure the user actually entered a
number.

Now you need to check whether the number is correct. If it is, call therandomnumber generator again and print out arandom"well done" message -
you can use a switch - if not, print out a "wrong answer message".

--
Free games and programming goodies.http://www.personal.leeds.ac.uk/~bgy1mm
this is what i have so far, don't laugh, i know it's horrible, but i
wanted to know if i'm going in the right direction... i think i'm lost
and confused
#include <stdlib.h>
#include <math.h>
#include <time.h>
#define num_val 1
int randnum (int k);
int product (void);
#define num1 (randnum)*1
#define num2 (randnum)+1

int main (void)
{
int num1= (randnum),
num2= ((randnum) +2);
int value, right, wrong;

srand (unsigned) time ();

printf ("Type -1 to exit!/n");
printf ("What is the product of %d and %d:/t", num1, num2);
scanf ("%d", &value);
if (value==-1)
printf ("Thanks for Playing, Goodbye!");
else (value == product)
printf ("Correct!");
else if (value!=product)
printf ("Wrong!");
}
return (0);
}
int randNum (int k)
{
int ranNum;
ranNum = 1 + (int) ( (float) k * rand() / ( RAND_MAX % 100 ) );
return (ranNum);
}
int product (int j)
{
int prod;
prod = num1 * num2;
return (prod);
}

Mar 6 '07 #5
On Mar 5, 1:46 pm, "Malcolm McLean" <regniz...@btinternet.comwrote:
<jjmillert...@hotmail.comwrote in message
I'm new so i apologize if this is in the wrong spot. I'm also new to
programming in C and i've been searching for quite a while on how to
create a program using C that willgeneratetworandomnumbers,
multiply them, and ask you for the result. It also needs to have four
responses for both right and wrong answers and should print them
randomly as well. The program should use at least 2 functions. Any
help would be greatly appreciated.

rand() willgeneratearandomnumber between 0 and RAND_MAX.
RAND_MAX is usually 32767, which is too high for arithmetic drill.

So get arandomnumber in the range 1 = 100 by taking modulus 100. There are
more accurate ways of doing this, but this should be fine now.

Unfortunately you program willgenerateexactly the same numbers on each
run. So call srand() with the time from time() to seed therandomnumber
generator.

Having got yourrandomnumbers, print them out with a message asking the
user to multiply. Then call scanf() to input the result. Don't forget to
check the return value of scanf() to make sure the user actually entered a
number.

Now you need to check whether the number is correct. If it is, call therandomnumber generator again and print out arandom"well done" message -
you can use a switch - if not, print out a "wrong answer message".

--
Free games and programming goodies.http://www.personal.leeds.ac.uk/~bgy1mm
ok this is what i have so far, don't laugh, i know it's probably
horrible, but if anyone could help with finishing it i would really
appreciate it

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#define num_val 1
int randnum (int k);
int product (int j);
#define num1 ((randnum)*1)
#define num2 ((randnum)+1)

int main (void)
{int value;

srand (unsigned) time ();

printf ("Type -1 to exit!/n");
printf ("What is the product of %d and %d:/t", num1, num2);
scanf ("%d", &value);
if (value==-1)
printf ("Thanks for Playing, Goodbye!");
else (value == product)
printf ("Correct!");
else if (value!=product)
printf ("Wrong!");
}
return (0);
}
int randNum (int k)
{
int ranNum;
ranNum = 1 + (int) ( (float) k * rand() / ( RAND_MAX % 100 ) );
return (ranNum);
}
int product (int j)
{
int prod;
prod = num1 * num2;
return (prod);
}

Mar 6 '07 #6
jjmillert...@hotmail.com wrote:
On Mar 5, 1:46 pm, "Malcolm McLean" <regniz...@btinternet.comwrote:
<jjmillert...@hotmail.comwrote in message
I'm new so i apologize if this is in the wrong spot. I'm also new to
programming in C and i've been searching for quite a while on how to
create a program using C that willgeneratetworandomnumbers,
multiply them, and ask you for the result. It also needs to have four
responses for both right and wrong answers and should print them
randomly as well. The program should use at least 2 functions. Any
help would be greatly appreciated.
rand() willgeneratearandomnumber between 0 and RAND_MAX.
RAND_MAX is usually 32767, which is too high for arithmetic drill.

So get arandomnumber in the range 1 = 100 by taking modulus 100. There are
more accurate ways of doing this, but this should be fine now.

Unfortunately you program willgenerateexactly the same numbers on each
run. So call srand() with the time from time() to seed therandomnumber
generator.

Having got yourrandomnumbers, print them out with a message asking the
user to multiply. Then call scanf() to input the result. Don't forget to
check the return value of scanf() to make sure the user actually entered a
number.
ok this is what i have so far, don't laugh, i know it's probably
horrible, but if anyone could help with finishing it i would really
appreciate it

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#define num_val 1
int randnum (int k);
int product (int j);
#define num1 ((randnum)*1)
#define num2 ((randnum)+1)
Wrong invocation of function randnum. It expects an int parameter,
according to your prototype above, but here you invoke it not only
without a parameter, but also without the parenthesis. A function call
must always have the accompanying parenthesis, even if there are no
arguments.
>
int main (void)
{int value;

srand (unsigned) time ();
srand((unsigned)time(NULL));
printf ("Type -1 to exit!/n");
Newline is '\n', not '/n'. In fact all C escape sequences start with a
'\', like '\t' for tab, '\a' for audible alert etc.
printf ("What is the product of %d and %d:/t", num1, num2);
Likewise '\t' for tab.
scanf ("%d", &value);
scanf is prone to failure. You should always check it's return value
before proceeding.
if (value==-1)
printf ("Thanks for Playing, Goodbye!");
else (value == product)
You mean an else if here, and an else below. Also, again you have to
supply the parenthesis around a function call. product also expects an
argument of type int.
printf ("Correct!");
else if (value!=product)
printf ("Wrong!");
Also always include a newline character at the end of printf strings
or alternatively call fflush(stdout) immediately afterwards, otherwise
output may appear delayed due to buffering.
}
return (0);
Parenthesis is redundant, but harmless.
}
int randNum (int k)
This function is never called in your code. C is case sensitive.
You've named this function randNum, but you invoke it as randnum,
(which is itself incorrect), above. It'll lead to a linkage error,
during compilation.
{
int ranNum;
ranNum = 1 + (int) ( (float) k * rand() / ( RAND_MAX % 100 ) );
Huh? Why so much contortion. Just:

return rand() % 100;

should do.
return (ranNum);
}

int product (int j)
{
int prod;
prod = num1 * num2;
return (prod);
}
Why're you invoking num1 and num2 again? You should use the previous
values. Each call to rand will return different values.

Mar 6 '07 #7
jj**********@hotmail.com wrote:
On Mar 5, 1:46 pm, "Malcolm McLean" <regniz...@btinternet.comwrote:
[ ... ]
create a program using C that willgeneratetworandomnumbers,
multiply them, and ask you for the result. It also needs to have four
responses for both right and wrong answers and should print them
randomly as well. The program should use at least 2 functions. Any
help would be greatly appreciated.
[ ... ]

Here's a short programme that may be similar to what you want:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void) {
int n1, n2;
long prd, guess;

srand((unsigned int)time(NULL));

n1 = 1 + (int)(100.0 * (rand() / (RAND_MAX + 1.0)));
n2 = 1 + (int)(100.0 * (rand() / (RAND_MAX + 1.0)));
prd = n1 * n2;

printf("What is the product of %d and %d\?\n"
"[Enter -1 to exit]\n", n1, n2);

if(scanf("%ld", &guess) != 1) {
puts("Incorrect input.");
return EXIT_FAILURE;
}
else if(guess == -1) {
puts("bye.");
}
else if(guess == prd) {
puts("Correct!");
}
else {
puts("Wrong guess.");
}
return 0;
}

Mar 6 '07 #8
On Mar 5, 10:44 pm, "santosh" <santosh....@gmail.comwrote:
jjmillert...@hotmail.com wrote:
On Mar 5, 1:46 pm, "Malcolm McLean" <regniz...@btinternet.comwrote:
<jjmillert...@hotmail.comwrote in message
I'm new so i apologize if this is in the wrong spot. I'm also new to
programming inCand i've been searching for quite a while on how to
create a programusingCthat willgeneratetworandomnumbers,
multiplythem, and ask you for the result. It also needs to have four
responses for both right and wrong answers and should print them
randomly as well. The program should use at least 2 functions. Any
help would be greatly appreciated.
rand() willgeneratearandomnumber between 0 and RAND_MAX.
RAND_MAX is usually 32767, which is too high for arithmetic drill.
So get arandomnumber in the range 1 = 100 by taking modulus 100. There are
more accurate ways of doing this, but this should be fine now.
Unfortunately you program willgenerateexactly the same numbers on each
run. So call srand() with the time from time() to seed therandomnumber
generator.
Having got yourrandomnumbers, print them out with a message asking the
user tomultiply. Then call scanf() to input the result. Don't forget to
check the return value of scanf() to make sure the user actually entered a
number.
ok this is what i have so far, don't laugh, i know it's probably
horrible, but if anyone could help with finishing it i would really
appreciate it
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#define num_val 1
int randnum (int k);
int product (int j);
#define num1 ((randnum)*1)
#define num2 ((randnum)+1)

Wrong invocation of function randnum. It expects an int parameter,
according to your prototype above, but here you invoke it not only
without a parameter, but also without the parenthesis. A function call
must always have the accompanying parenthesis, even if there are no
arguments.
int main (void)
{int value;
srand (unsigned) time ();

srand((unsigned)time(NULL));
printf ("Type -1 to exit!/n");

Newline is '\n', not '/n'. In fact allCescape sequences start with a
'\', like '\t' for tab, '\a' for audible alert etc.
printf ("What is the product of %d and %d:/t", num1, num2);

Likewise '\t' for tab.
scanf ("%d", &value);

scanf is prone to failure. You should always check it's return value
before proceeding.
if (value==-1)
printf ("Thanks for Playing, Goodbye!");
else (value == product)

You mean an else if here, and an else below. Also, again you have to
supply the parenthesis around a function call. product also expects an
argument of type int.
printf ("Correct!");
else if (value!=product)
printf ("Wrong!");

Also always include a newline character at the end of printf strings
or alternatively call fflush(stdout) immediately afterwards, otherwise
output may appear delayed due to buffering.
}
return (0);

Parenthesis is redundant, but harmless.
}
int randNum (int k)

This function is never called in your code.Cis case sensitive.
You've named this function randNum, but you invoke it as randnum,
(which is itself incorrect), above. It'll lead to a linkage error,
during compilation.
{
int ranNum;
ranNum = 1 + (int) ( (float) k * rand() / ( RAND_MAX % 100 ) );

Huh? Why so much contortion. Just:

return rand() % 100;

should do.
return (ranNum);
}
int product (int j)
{
int prod;
prod = num1 * num2;
return (prod);
}

Why're you invoking num1 and num2 again? You should use the previous
values. Each call to rand will return different values.
ok, i'm not sure if i fixed everything you were talking about, but i
hope i did, thank you so much for your help, this is for homework and
my teacher basically just tells us different parts of things but never
really explains how to put anything together and its really irritating
because i'm usually fairly computer literate
int main (void)
{int value,product;
//set and seed rand
srand ((unsigned) time (NULL));
printf ("Type -1 to exit!\n");
printf ("What is the product of %d and %d:\t", num1, num2);
scanf ("%d", &value);
product = ((num1) * (num2))
//if value is -1, end program
if (value!=-1)
printf ("OK, Goodbuy!\n");
else if ((value) == (product))
printf ("Correct!\n");
else ((value)!=(product))
printf ("Wrong!\n");
}
return (0);
}
//first function
int randnumber (int k)
{
int random;
return rand() % 100;
return (random);
}

Mar 6 '07 #9
wow, thats so much cleaner, could you help me put another function
into it so it will have 4 correct answers (eg "Thats right!") and 4
wrong ("sorry try again") i know you probably have better things to
do, but i have to hand it in in 30 minutes, and obviously i don't know
what i'm doing

Mar 6 '07 #10
jj**********@hotmail.com wrote:
On Mar 5, 10:44 pm, "santosh" <santosh....@gmail.comwrote:
jjmillert...@hotmail.com wrote:
On Mar 5, 1:46 pm, "Malcolm McLean" <regniz...@btinternet.comwrote:
<jjmillert...@hotmail.comwrote in message
[ ... ]
create a programusingCthat willgeneratetworandomnumbers,
>multiplythem, and ask you for the result. It also needs to have four
responses for both right and wrong answers and should print them
randomly as well. The program should use at least 2 functions. Any
help would be greatly appreciated.
[ ... ]
ok this is what i have so far, don't laugh, i know it's probably
horrible, but if anyone could help with finishing it i would really
appreciate it
[ ... ]
ok, i'm not sure if i fixed everything you were talking about, but i
hope i did, thank you so much for your help, this is for homework and
my teacher basically just tells us different parts of things but never
really explains how to put anything together and its really irritating
because i'm usually fairly computer literate
int main (void)
{int value,product;
//set and seed rand
srand ((unsigned) time (NULL));
printf ("Type -1 to exit!\n");
printf ("What is the product of %d and %d:\t", num1, num2);
Since you're not terminating your printf string with a newline, call
fflush(stdout) after it.
Additionally, I hope you've fixed your num1 and num2 macros.
scanf ("%d", &value);
product = ((num1) * (num2))
Here's a mistake. Each invocation of the rand function returns
different values. The two invocations above will not return the same
values as the invocations within the printf statement earlier. So, in
effect, you're computing a product to two different integers than what
you presented to the user earlier.
//if value is -1, end program
if (value!=-1)
if(value == -1)
printf ("OK, Goodbuy!\n");
else if ((value) == (product))
printf ("Correct!\n");
else ((value)!=(product))
printf ("Wrong!\n");
}
return (0);
}
//first function
int randnumber (int k)
{
int random;
Don't use the identifier random. There're certain popular non-standard
functions that use that name.
return rand() % 100;
ITYM random = rand() % 100;

But to get even better randomness do:

random = 1 + (int)(100.0 * (rand() / (RAND_MAX + 1.0)));

This uses the higher order bits of the value that rand returns, which
are more random than the lower order bits.
return (random);
Again the parenthesis aren't necessary.
}
Mar 6 '07 #11
jj**********@hotmail.com wrote:
wow, thats so much cleaner, could you help me put another function
into it so it will have 4 correct answers (eg "Thats right!") and 4
wrong ("sorry try again") i know you probably have better things to
do, but i have to hand it in in 30 minutes, and obviously i don't know
what i'm doing
Try this:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define CORRECT 1
#define INCORRECT 0

void print_rand_msg(const int msg_type);

int main(void) {
int n1, n2;
long prd, guess;

srand((unsigned int)time(NULL));

n1 = 1 + (int)(100.0 * (rand() / (RAND_MAX + 1.0)));
n2 = 1 + (int)(100.0 * (rand() / (RAND_MAX + 1.0)));
prd = n1 * n2;

printf("What is the product of %d and %d\?\n"
"[Enter -1 to exit]\n", n1, n2);

if(scanf("%ld", &guess) != 1) {
puts("Incorrect input.");
return EXIT_FAILURE;
}
else if(guess == -1) {
puts("bye.");
}
else if(guess == prd) {
print_rand_msg(CORRECT);
}
else {
print_rand_msg(INCORRECT);
}
return 0;
}

void print_rand_msg(const int type) {
char *correct_msgs[4] = { "Correct", "You're right!", "Perfect!",
"You've hit the nail on the head!" };
char *incorrect_msgs[4] = { "Wrong.", "Bad luck, try again",
"Waaay of target.", "Not even close." };
const int rndidx = 1 + (int)(4.0 * (rand() / (RAND_MAX + 1.0)));

switch (type) {
case CORRECT:
puts(correct_msgs[rndidx]);
break;
case INCORRECT:
puts(incorrect_msgs[rndidx]);
break;
default:
puts("Wrong argument.");
exit(EXIT_FAILURE);
}
return;
}

Mar 6 '07 #12
On Mar 5, 11:58 pm, "santosh" <santosh....@gmail.comwrote:
jjmillert...@hotmail.com wrote:
wow, thats so much cleaner, could you help me put another function
into it so it will have 4 correct answers (eg "Thats right!") and 4
wrong ("sorry try again") i know you probably have better things to
do, but i have to hand it in in 30 minutes, and obviously i don't know
what i'm doing

Try this:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define CORRECT 1
#define INCORRECT 0

void print_rand_msg(const int msg_type);

int main(void) {
int n1, n2;
long prd, guess;

srand((unsigned int)time(NULL));

n1 = 1 + (int)(100.0 * (rand() / (RAND_MAX + 1.0)));
n2 = 1 + (int)(100.0 * (rand() / (RAND_MAX + 1.0)));
prd = n1 * n2;

printf("What is the product of %d and %d\?\n"
"[Enter -1 to exit]\n", n1, n2);

if(scanf("%ld", &guess) != 1) {
puts("Incorrect input.");
return EXIT_FAILURE;
}
else if(guess == -1) {
puts("bye.");
}
else if(guess == prd) {
print_rand_msg(CORRECT);
}
else {
print_rand_msg(INCORRECT);
}
return 0;

}

void print_rand_msg(const int type) {
char *correct_msgs[4] = { "Correct", "You're right!", "Perfect!",
"You've hit the nail on the head!" };
char *incorrect_msgs[4] = { "Wrong.", "Bad luck, try again",
"Waaay of target.", "Not even close." };
const int rndidx = 1 + (int)(4.0 * (rand() / (RAND_MAX + 1.0)));

switch (type) {
case CORRECT:
puts(correct_msgs[rndidx]);
break;
case INCORRECT:
puts(incorrect_msgs[rndidx]);
break;
default:
puts("Wrong argument.");
exit(EXIT_FAILURE);
}
return;

}
thanks so much for your help, i really appreciate it

Mar 6 '07 #13
On 5 Mar 2007 22:05:31 -0800, in comp.lang.c ,
jj**********@hotmail.com wrote:
>On Mar 5, 11:58 pm, "santosh" <santosh....@gmail.comwrote:
>jjmillert...@hotmail.com wrote:
do, but i have to hand it in in 30 minutes, and obviously i don't know
what i'm doing

Try this:
(snip example)
>
thanks so much for your help, i really appreciate it
Make sure you spend the time to understand it, so that when your
teacher asks, you will be able to answer.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Mar 6 '07 #14
Daniel Rudy wrote:
>
At about the time of 3/5/2007 7:23 AM, jj**********@hotmail.com stated
the following:
I'm new so i apologize if this is in the wrong spot. I'm also new to
programming in C and i've been searching for quite a while on how to
create a program using C that will generate two random numbers,
multiply them, and ask you for the result. It also needs to have four
responses for both right and wrong answers and should print them
randomly as well. The program should use at least 2 functions. Any
help would be greatly appreciated.

Thanks

Homework?

Go take a look and rand(3) and srand(3). It's standard C.

http://www.acm.uiuc.edu/webmonkeys/book/c_guide/
What is rand(3) supposed to mean?

--
pete
Mar 11 '07 #15

pete wrote:
Daniel Rudy wrote:

At about the time of 3/5/2007 7:23 AM, jj**********@hotmail.com stated
the following:
I'm new so i apologize if this is in the wrong spot. I'm also new to
programming in C and i've been searching for quite a while on how to
create a program using C that will generate two random numbers,
multiply them, and ask you for the result. It also needs to have four
responses for both right and wrong answers and should print them
randomly as well. The program should use at least 2 functions. Any
help would be greatly appreciated.
>
Thanks
>
Homework?

Go take a look and rand(3) and srand(3). It's standard C.

http://www.acm.uiuc.edu/webmonkeys/book/c_guide/

What is rand(3) supposed to mean?
I think he meant to say man 3 rand.

Mar 12 '07 #16
pete <pf*****@mindspring.comwrites:
Daniel Rudy wrote:
[...]
>Go take a look and rand(3) and srand(3). It's standard C.

http://www.acm.uiuc.edu/webmonkeys/book/c_guide/

What is rand(3) supposed to mean?
<OT>
Under Unix, "rand(3)" refers to the man page for the rand function in
section 3 of the manual; you can use "man 3 rand" or "man -s 3 rand"
to read it.
</OT>

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Mar 12 '07 #17
pete wrote:
Daniel Rudy wrote:
.... snip ...
>>
Go take a look and rand(3) and srand(3). It's standard C.

http://www.acm.uiuc.edu/webmonkeys/book/c_guide/

What is rand(3) supposed to mean?
It means, on unixy systems, enter "man N topic". Here it would
translate to "man 3 rand".

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account from http://www.teranews.com

Mar 12 '07 #18
CBFalconer wrote:
pete wrote:
>Daniel Rudy wrote:
.... snip ...
>>Go take a look and rand(3) and srand(3). It's standard C.

http://www.acm.uiuc.edu/webmonkeys/book/c_guide/
What is rand(3) supposed to mean?

It means, on unixy systems, enter "man N topic". Here it would
translate to "man 3 rand".
I think it was man -M 3 rand on Solaris 2.7 but the -M is no
longer necessary on Linux systems.

--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it's not too late)
(... and that it still works...)
Mar 12 '07 #19
Nelu <sp*******@gmail.comwrites:
CBFalconer wrote:
>pete wrote:
>>Daniel Rudy wrote:
.... snip ...
>>>Go take a look and rand(3) and srand(3). It's standard C.

http://www.acm.uiuc.edu/webmonkeys/book/c_guide/
What is rand(3) supposed to mean?

It means, on unixy systems, enter "man N topic". Here it would
translate to "man 3 rand".

I think it was man -M 3 rand on Solaris 2.7 but the -M is no
longer necessary on Linux systems.
<OT>
Not quite. "man man" for details. (If you don't have the "man"
command, then you don't need to know how it works.)
</OT>

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Mar 12 '07 #20
Keith Thompson wrote:
Nelu <sp*******@gmail.comwrites:
>CBFalconer wrote:
>>pete wrote:
Daniel Rudy wrote:

.... snip ...
Go take a look and rand(3) and srand(3). It's standard C.
>
http://www.acm.uiuc.edu/webmonkeys/book/c_guide/
What is rand(3) supposed to mean?
It means, on unixy systems, enter "man N topic". Here it would
translate to "man 3 rand".
I think it was man -M 3 rand on Solaris 2.7 but the -M is no
longer necessary on Linux systems.

<OT>
Not quite. "man man" for details. (If you don't have the "man"
command, then you don't need to know how it works.)
</OT>
<OT>
I no longer have access to Solaris :-(, only to Linux. But I seem
to remember that on Solaris you needed to specify the section
number using a switch. It seems it was -s not -M :-). I was
talking about dropping the option in the context of same use on
Linux vs. Solaris man applications, -M has a different meaning on
Linux... but it doesn't matter... it's -s anyway :-).
</OT>

--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org (hope it's not too late)
(... and that it still works...)
Mar 12 '07 #21

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Laphan | last post by:
Hi All This is a strange request, but I just cannot fathom how to do it. In theory the requirement is very basic, but in practise its a noodle!! I have 10 team names like so: Team A Team...
70
by: Ben Pfaff | last post by:
One issue that comes up fairly often around here is the poor quality of the pseudo-random number generators supplied with many C implementations. As a result, we have to recommend things like...
4
by: Marc Dansereau | last post by:
Hi all, I wonder what is the most efficient way to generate random point on a line defined by 2 double points (x0,y0) and (x1,y1). Here is the pseudocode of my method : for each point {...
2
by: Henry | last post by:
Hi, How can I generate an eight digit random? Can I use the staff name to generate it? May I ask is there any sample c# code to see? Thanks
12
by: Jim Michaels | last post by:
I need to generate 2 random numbers in rapid sequence from either PHP or mysql. I have not been able to do either. I get the same number back several times from PHP's mt_rand() and from mysql's...
15
by: Orchid | last post by:
Hello, I am looking to generate a unique ID field on MS. Access. The ID is with 10 digits with the combination of 5 Letters from the 26 letters and 5 Numbers from 1 to 9. The letters and numbers...
12
by: Juha Nieminen | last post by:
I'm trying to use a random number generator and rand() is just not up to the task (RAND_MAX is way too small). I searched in the help system and found the System::Random class which seems to be...
9
by: Chelong | last post by:
Hi All I am using the srand function generate random numbers.Here is the problem. for example: #include<iostream> #include <time.h> int main() {
13
by: Nick | last post by:
Hi there, I'm trying to create a random number via a seed in VB.NET and C++, 2 different applications. I want to be able to use the same seed and get the same random number but unfortunately...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.