Back to index

glibc  2.9
Functions
strfry.c File Reference
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>

Go to the source code of this file.

Functions

char * strfry (char *string)

Function Documentation

char* strfry ( char *  string)

Definition at line 25 of file strfry.c.

{
  static int init;
  static struct random_data rdata;

  if (!init)
    {
      static char state[32];
      rdata.state = NULL;
      __initstate_r (time ((time_t *) NULL) ^ getpid (),
                   state, sizeof (state), &rdata);
      init = 1;
    }

  size_t len = strlen (string);
  if (len > 0)
    for (size_t i = 0; i < len - 1; ++i)
      {
       int32_t j;
       __random_r (&rdata, &j);
       j = j % (len - i) + i;

       char c = string[i];
       string[i] = string[j];
       string[j] = c;
      }

  return string;
}

Here is the call graph for this function:

Here is the caller graph for this function: