I am planning to create a simple bulls and cows( also know as mastermind board game) in C.The computer is supposed to make 4 digit code in which the allowed digits are 1,2,3,4,5,and 6 ! 0,7,8,9 are to omitted !! How do I make the computer create such a 4 digit number? I know about rand() function !! But how do I make it omit those 4 digits?
jeevsmyd -2 Junior Poster
Recommended Answers
Jump to Postrand() can give you a specific range of random numbers. Just set it up for 1 to 5, four times.
1
2
3
5Inside a loop, you can put the "number" together, from those digits if you want:
5 * 10^0 +
3 * 10^1 +
2 …
Jump to Postrand() will give you the SAME sequence of random numbers every time (it's used that way for testing programs and equipt.).
srand() will give rand() a new starting place or "seed"
/* resets the random number function, based on system time */ time_t t; srand(time(&t));
All …
All 8 Replies
Adak 419 Nearly a Posting Virtuoso
Auraomega 2 Junior Poster in Training
jeevsmyd -2 Junior Poster
Adak 419 Nearly a Posting Virtuoso
jeevsmyd -2 Junior Poster
Auraomega 2 Junior Poster in Training
jeevsmyd -2 Junior Poster
Auraomega 2 Junior Poster in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.