| | |
random string
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
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 * ansi append array arrays asterisks binarysearch calculate changingto char character cm convert copyimagefile cprogramme creafecopyofanytypeoffileinc database dynamic execv feet fflush fgets file fork forloop framework function getlasterror givemetehcodez grade gtkwinlinux hacking hardware histogram inches include incrementoperators input intmain() iso kernel keyboard km license linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix microsoft motherboard mqqueue number oddnumber odf opendocumentformat opensource overwrite owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv recvblocked research reversing scanf scripting segmentationfault sequential socket socketprograming standard string systemcall testing threads turboc unix user variable voidmain() wab whythiscodecausesegmentationfault windowsapi






