Randomizing
Is there any function for randomizing a string (like glibc's strfry() ) which
can be used across different Unices ?
Khoda Hafez
Progga
Quoted 2 lines · Progga
Is there any function for randomizing a string (like glibc's
strfry()) which can be used across different Unices ?
No; but it's not hard to write one yourself:
void randomize(char *str)
{
int len = strlen(str);
int i;
for (i = 0; i < len; i++)
{
int n = i + rand() % (len - i);
char tmp = str[i];
str[i] = str[n];
str[n] = tmp;
}
}Signature · 1 line
Glynn Clements <[email protected]>