I am trying to make a program that gets words from three list and makes a phrase with them. Such as a noun list an adjetive list and an adverb list, to randomly generate object ideas for a game i am writing. I dont want it to be flashy, i just want something i can go back into and edit the lists whenever i want to add things to it.
How do you make a randomly generated list in C++?
http://members.cox.net/srice1/random/cra...
shows the c++ rand function.
Reply:You can use the rand() function to generate a random number. Note that this generates a double between [0, 1). To turn this into an integer, I normally define a macro:
#define randint(min, max) (((int(rand() * 10e9)) % ((max) - (min) + 1)) + (min))
The first part turns the random fractional double into an integer from [0, 10e9]. The second part turns that integer into a number from [0, max - min]. The third part makes it [min, max].
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment