Index: base/rand_util.cc |
=================================================================== |
--- base/rand_util.cc (revision 83409) |
+++ base/rand_util.cc (working copy) |
@@ -41,4 +41,20 @@ |
return base::RandUint64() % max; |
} |
+std::string RandString(int length) { |
+ const size_t kBitsPerChar = 8; |
+ const int kCharsPerInt64 = sizeof(uint64)/sizeof(char); |
+ |
+ std::string result(length, '\0'); |
+ uint64 entropy = 0; |
+ for (size_t i = 0; i < result.size(); ++i) { |
+ if (i % kCharsPerInt64 == 0) |
+ entropy = RandUint64(); |
darin (slow to review)
2011/04/29 16:15:36
nit: indentation
|
+ result[i] = static_cast<char>(entropy); |
+ entropy >>= kBitsPerChar; |
+ } |
+ |
+ return result; |
+} |
+ |
} // namespace base |