samedi 28 octobre 2017

How to get a random number in a specific range for C++? [duplicate]

This question already has an answer here:

I have been programming in python for 2 years and recently started learning C++. In python we can use random.randint(32,122) to generate a random which in this case is between 32 and 122. I am aware of rand() in c++ but it requires seeds from the time which can cause duplicates. It also doesn't allow a minimum value as far as i am aware only a maximum. If anyone can help it'd be appreciated. If it helps these numbers will be used in an encryption program so the random number will represent an ASCII key hence the 32 to 122, it is very much needed to not get duplicates. Thanks.




Aucun commentaire:

Enregistrer un commentaire