summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-04-09 17:48:52 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-04-09 17:48:52 +0000
commitca7ac1c188c3ab3b70617ec6eea14afa86d43053 (patch)
tree40f4b74e64fb5b824dd037c42b16932017e6addb
parent54f4abc93d1fd498ce1cfe6f4a3ccc62f03af6bc (diff)
Different way of generating random string
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6779 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--src/modules/m_spanningtree/treesocket1.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/modules/m_spanningtree/treesocket1.cpp b/src/modules/m_spanningtree/treesocket1.cpp
index 55822cf47..39a32e6f4 100644
--- a/src/modules/m_spanningtree/treesocket1.cpp
+++ b/src/modules/m_spanningtree/treesocket1.cpp
@@ -264,9 +264,25 @@ std::string TreeSocket::MyCapabilities()
std::string TreeSocket::RandString(unsigned int length)
{
+ char* randombuf = new char[length+1];
std::string out;
+ int fd = open("/dev/urandom", O_RDONLY, 0);
+
+ if (fd >= 0)
+ {
+ read(fd, randombuf, length);
+ close(fd);
+ }
+ else
+ {
+ for (unsigned int i = 0; i < length; i++)
+ randombuf[i] = rand();
+ }
+
for (unsigned int i = 0; i < length; i++)
- out += static_cast<char>((rand() % 26) + 65);
+ out += static_cast<char>((randombuf[i] & 0x7F) | 0x21);
+
+ delete[] randombuf;
return out;
}