Today was another C++ day.
I've pretty much mastered the basics of C++. From memory, I can structure a C++ document, input and output information from the console, declare and give value to variables, create while, do, and for loops, and if/else statements.
While I have mastered that much, it's only a small amount of the language. There is still LOTS I have to learn.
The newest thing I learned today was how to create random numbers. I only learned how to use the simplified rand() function, but it will serve me well for now. There is a much more complex way of producing random numbers, which also produces a better result, but that is past my current skill level.
23 comments:
I'm interested in learning C++, how long has it taken you to get to the stage you're at?
random number generators have so many uses. Gratz!
Good to hear you are progressing! Keep up the good work.
oh man i dabbled in C ages ago
C+ is interesting :)
I tried my luck with some C++, wasn't for me. Maybe I'll have another go.
i actually wanted to go to school for ths.. but isnt stuff like this bieng sent overseas
I've always wanted to code...good luck.
Im a programmar myself. As long as you've got determination, you'll get there.
When you said produce a random number, do you mean like a random number generator digital dice?
Niice man.
One thing about generating random numbers with rand(), typically to get numbers within a certain range you will want to use the modulus. You can divide a random number by say... 15 and the remainder is guaranteed to be less than 15 :)
Also, you'll want to call srand() ONCE for the lifetime of the program, usually at the beginning of the program. It's not really necessary to use the same seed, but if you call it too often your numbers will be much less random.
seeding with the time is usually good:
#include
#include
#include
const int UPPER_BOUND = 15;
int main(){
srand(static_cast(time(NULL)));
for(int i = 0; i < 10; i++)
std::cout << rand()%UPPER_BOUND << std::endl;
}
well it removed the from the static_cast so apparently this comment box doesn't support code very well...
woops it did it again, sorry I'm an idiot.
"less than" unsigned int "greater than".
coding is nice! Keep the good work dude!
You should code duke nukem forever 2
coding is tough man,nice job for learning that much
I wish you luck with learning, i need it too.
i wish i could do that too
I remembered when I first learned all that. I realized that learning the basics of C++ is all well and good, but much of that information can be looked up when I needed it.
interested in this, I don't know if I would get bored in coding/programming though
Good luck with it.
Good tips
@Jimmy, if you're worried about failure then you've already failed.
Post a Comment