From ca7ac1c188c3ab3b70617ec6eea14afa86d43053 Mon Sep 17 00:00:00 2001 From: brain Date: Mon, 9 Apr 2007 17:48:52 +0000 Subject: Different way of generating random string git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6779 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules/m_spanningtree/treesocket1.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src') 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((rand() % 26) + 65); + out += static_cast((randombuf[i] & 0x7F) | 0x21); + + delete[] randombuf; return out; } -- cgit v1.2.3