From ac2dc42f1840dcd9cfb13f36399590c8620d1501 Mon Sep 17 00:00:00 2001 From: psychon Date: Sat, 10 May 2008 06:46:53 +0000 Subject: [PATCH] Make CString::RandomString() produce something more random Instead of A-Z we now use A-Z,a-z,0-9,!?.,:;/*-+() This means our random strings are now 2.5 times more random :). git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1047 726aef4b-f618-498e-8847-2d620e286838 --- String.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/String.cpp b/String.cpp index 93afc57f..56d144c8 100644 --- a/String.cpp +++ b/String.cpp @@ -662,10 +662,16 @@ CString CString::Format(const CString& sFormatStr, ...) { } CString CString::RandomString(unsigned int uLength) { + const char chars[] = "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789!?.,:;/*-+_()"; + const size_t len = sizeof(chars) / sizeof(char); + size_t p; CString sRet; for (unsigned int a = 0; a < uLength; a++) { - sRet += (char) (rand() % 26) + 65; + p = (size_t) (len * (rand() / (RAND_MAX + 1.0))); + sRet += chars[p]; } return sRet;