Click to See Complete Forum and Search --> : random character generation


cheahyw
03-05-2004, 05:58 AM
hi all,

im a c++ newbiw & struggling with my socket programming assignment now. my assignment require me to generate 4 char with "\" after it.
EG: char msgsent[1000]={"uwms\", "dfas\","asdk\",...}

just wondering is there is smarter way to generate these char instead of manually set?

please help here....thanks alot.

i can post my code if need be.

Danny
03-05-2004, 06:41 AM
Sure there is. The random_shuffle() algorithm for example can do this easily: http://www.devx.com/DevX/LegacyLink/9467

Remmeber however that this algorithm doesn't really generate random values by default but psedo random values, i.e., you'll get the same "random" characters every time you run the program. In many cases, this is sufficient but if you need truly random values, you'll have to use a different method.