| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/rand_util.h" | 5 #include "base/rand_util.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 | 8 |
| 9 #include <algorithm> |
| 10 |
| 9 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 10 #include "base/logging.h" | 12 #include "base/logging.h" |
| 11 | 13 |
| 12 namespace { | 14 namespace { |
| 13 | 15 |
| 14 uint32 RandUint32() { | 16 uint32 RandUint32() { |
| 15 uint32 number; | 17 uint32 number; |
| 16 CHECK_EQ(rand_s(&number), 0); | 18 CHECK_EQ(rand_s(&number), 0); |
| 17 return number; | 19 return number; |
| 18 } | 20 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 32 uint64 random_int; | 34 uint64 random_int; |
| 33 const size_t random_int_size = sizeof(random_int); | 35 const size_t random_int_size = sizeof(random_int); |
| 34 for (size_t i = 0; i < output_length; i += random_int_size) { | 36 for (size_t i = 0; i < output_length; i += random_int_size) { |
| 35 random_int = base::RandUint64(); | 37 random_int = base::RandUint64(); |
| 36 const size_t copy_count = std::min(output_length - i, random_int_size); | 38 const size_t copy_count = std::min(output_length - i, random_int_size); |
| 37 memcpy(((uint8*)output) + i, &random_int, copy_count); | 39 memcpy(((uint8*)output) + i, &random_int, copy_count); |
| 38 } | 40 } |
| 39 } | 41 } |
| 40 | 42 |
| 41 } // namespace base | 43 } // namespace base |
| OLD | NEW |