| | |
random string
![]() |
Create a string containing all the letters you want to use. Seed and use rand() to access elements (using the % operator to force the numbers within the string's range). Strcat in a loop. Pseudo-code.
Or something like that. Alternatively you could just rand() (limit up to 25) and add 'a' onto the number and append that to your string. I think the above method is better though because you can extend the characters you use (you could put numbers, symbols, capital letters in it). That is harder to do with the second method I mentioned.
c Syntax (Toggle Plain Text)
my_letters = "abcdefghijklmnopqrstuvwxyz" /* allowable letters for your random string */ my_random_string /* your random string. Initially empty */ srand( time(0) ) /* seed rand */ for i=0 to 10 /* or however long you want it */ append( my_random_string, /* append to this string */ my_letters[rand()%strlen(my_random_string)] ) /* this letter */ end loop
Last edited by twomers; Oct 28th, 2007 at 8:12 am.
Use a loop to generate as many random numbers from 0 to 25 as you want and add the values to the string. When you get the random number, simply add 'a' to it and you will have all letters instead of 0-25
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
![]() |
Similar Threads
- Hidden program installs .dlls with randomly generated names in random "notify" reg. (Viruses, Spyware and other Nasties)
- Create sentences using random num generation (C)
- Function that creates random changes in a string?? (Python)
- How to "seperate" numbers from String? (Java)
- I don't know how to start to determine what hand of the poker, any ideas??? (Java)
- Duplication (C++)
Other Threads in the C Forum
- Previous Thread: C program
- Next Thread: Problem when passing a structure containing an array of 2D-chars array to a function
| Thread Tools | Search this Thread |
#include adobe ansi api array asterisks binarysearch changingto char character cm copyimagefile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax database directory dynamic execv feet fgets file fork forloop frequency function getlasterror givemetehcodez global grade graphics gtkgcurlcompiling hacking hardware highest histogram i/o include incrementoperators infiniteloop input interest kernel keyboard kilometer license linked linkedlist linux linuxsegmentationfault list locate logical_drives looping loopinsideloop. lowest match matrix meter microsoft motherboard mqqueue mysql number odf opensource owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv repetition research reversing scanf segmentationfault sequential shape socket socketprograming standard string systemcall threads turboc unix user voidmain() wab windows.h windowsapi






