Ask your own question, for FREE!
Mathematics 9 Online
OpenStudy (calculusxy):

Need help with C Programming!

OpenStudy (calculusxy):

How do you make C choose a random number between a range (for example 2 to 6)?

OpenStudy (xlpoisonpotato):

dude this is mathematics not programming

OpenStudy (cazeh):

lol

OpenStudy (calculusxy):

But where do I possibly ask a programming question? The Computer Science section is not even so active.

OpenStudy (cazeh):

Then, English

OpenStudy (calculusxy):

That doesn't make any sense.

OpenStudy (cazeh):

sry

OpenStudy (xlpoisonpotato):

idk man

OpenStudy (xlpoisonpotato):

google?

OpenStudy (tkhunny):

There's enough mathematics in this question, I think. Are we rolling dice? Use the rand() function. This should produce [0,1] It uses a fixed seed, so it you want it to be more random, you should use srand(unisgned int seed) . Default seed is 1. Careful how you manipulate this. If you multiply by 6 and round, you may not get what you expect.

OpenStudy (calculusxy):

@tkhunny Here's a program that I wrote to generate a random number between 2 and 6. #include <stdio.h> { int random_number; srand(time(NULL)); random_number = rand() % 7 + 2; printf("%d\n", random_number); return 0; } But I get an error when I compile it. Can you please check it?

OpenStudy (cazeh):

Click the key and r It will open Command run, then go to roaming then you can use it.

OpenStudy (tkhunny):

Two things: 1) Is TIME() integer? 2) Why would % 7 + 2 be [2-6]? I don't know much about it. C isn't really where I live.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Latest Questions
XShawtyX: Art, Short Writing Assignment: Imagining Landscapes
5 hours ago 2 Replies 0 Medals
XShawtyX: Chemistry, Help ud83dude4fud83cudffe
6 hours ago 13 Replies 1 Medal
kaelynw: tried a lil smt, the arm is off but i like the other stuff
16 hours ago 27 Replies 3 Medals
kaelynw: art igg
15 hours ago 14 Replies 2 Medals
XShawtyX: Art
3 days ago 6 Replies 0 Medals
Nina001: teach me how to draw or just tell me the basics
3 days ago 2 Replies 1 Medal
XShawtyX: We doing another drawing gimme ideas to add to this
3 days ago 9 Replies 1 Medal
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!