I am trying to make a blackjack game, where the user gets a pair of cards, and the dealer gets a pair of cards. My problem is that right now they are getting the same pair of cards, and I don't know how to change the random number generator. Here is what I have:
I have that for both the dealer and the user. I understand that it will give me the same random numbers, but how can I generate a different number for the user? I cannot put (1) in where the 0 is (which is what I thought would do it).
Is there a better way to use random numbers?
Edit: Side note. I don't know if this matters, but about 10% of the time when I run it, the complier gives me some random symbol instead of a number between 2-14. I don't know if this is something to do with my other code, or this code.
rand() generates a different random number every time. I believe it seeds itself using the last number generated. Your code should be fine, so you must have a problem elsewhere.
Do note that rand() isn't generally considered a very good RNG. It simply generates a predictable "random" series of numbers based on the seed. If you pass it the same seed you'll get the same series.
PSEUDO EDIT: If you call srand(time(0)) both times then you will initialize the generator with the second you started the program at again, causing the start of the same sequence. Only call srand once, at the beginning of your program.
ACTUAL EDIT: I guess I had time figured wrong all this time. Good thing I never used it :P The argument you pass is a pointer to a time object which the function uses to store the current time value. Although the thing about calling srand only once still stands.
And your error probably still comes from the fact that you call srand twice, (if this is what you do) since those sections of code most probably likely definitely take less than 1 second to execute.