linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Randomizing
@ 2003-04-12 14:44 Progga
  2003-04-12 15:40 ` Randomizing Glynn Clements
  0 siblings, 1 reply; 2+ messages in thread
From: Progga @ 2003-04-12 14:44 UTC (permalink / raw)
  To: linux-c-programming


 Is there any function for randomizing a string (like glibc's strfry() ) which 
can be used across different Unices ?

 Khoda Hafez
 Progga


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Randomizing
  2003-04-12 14:44 Randomizing Progga
@ 2003-04-12 15:40 ` Glynn Clements
  0 siblings, 0 replies; 2+ messages in thread
From: Glynn Clements @ 2003-04-12 15:40 UTC (permalink / raw)
  To: Progga; +Cc: linux-c-programming


Progga wrote:

> 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;
		}
	}

-- 
Glynn Clements <glynn.clements@virgin.net>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-04-12 15:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-04-12 14:44 Randomizing Progga
2003-04-12 15:40 ` Randomizing Glynn Clements

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).