Adventures in Game Development -- Day 5



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.

24 comments:

tkNova said...

I'm interested in learning C++, how long has it taken you to get to the stage you're at?

Geoffrey said...

random number generators have so many uses. Gratz!

Rumiko said...

Good to hear you are progressing! Keep up the good work.

Jesse Crows said...

oh man i dabbled in C ages ago

! creator ! said...

C+ is interesting :)

Stephen said...

I tried my luck with some C++, wasn't for me. Maybe I'll have another go.

JustAnotherBloggerNamedCisco said...

i actually wanted to go to school for ths.. but isnt stuff like this bieng sent overseas

Volturno Caravaggio said...

I've always wanted to code...good luck.

pietah said...

Im a programmar myself. As long as you've got determination, you'll get there.

Jack Burton said...

When you said produce a random number, do you mean like a random number generator digital dice?

jblogger45 said...

interesting

happyhacker said...

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;
}

happyhacker said...

well it removed the from the static_cast so apparently this comment box doesn't support code very well...

happyhacker said...

woops it did it again, sorry I'm an idiot.
"less than" unsigned int "greater than".

CharlesS said...

coding is nice! Keep the good work dude!

Things on my wishlist said...

You should code duke nukem forever 2

mwesten said...

coding is tough man,nice job for learning that much

Triper said...

I wish you luck with learning, i need it too.

nowbuddy said...

i wish i could do that too

Ivan said...

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.

Jimmy said...

interested in this, I don't know if I would get bored in coding/programming though

Jay Reid said...

Good luck with it.

TK1927 said...

Good tips

happyhacker said...

@Jimmy, if you're worried about failure then you've already failed.

Post a Comment