Hi
Does any know if there is any code i can use to generate random letters or numbers?
Hi
Does any know if there is any code i can use to generate random letters or numbers?
Check the FAQ.
Mainframe assembler programmer by trade. C coder when I can.
Generally, you can use rand() to generate random numbers. You can then use modulo and addition to make it the range you want.
Generically:
Of course for digits, this can be simplified:Code:int x = rand() % (1 + max - min) + min;
--Code:char ch = rand() % 10 + '0';
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
thanks guys i got some info on the numbers.
Any ideas for characters?
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
For a guarenteed character range, you could create use a string with an acceptable alphabet, and then use the random number as an index.