1
Septembers 2015-03-29 08:08:05 +08:00
OpenSSL
|
2
linux40 2015-03-29 08:39:19 +08:00 via Android
cstdlib伪随机算不算。。。
|
3
tobyxdd 2015-03-29 08:41:43 +08:00 via Android
你是要自己写算法还是只要实现
|
4
Landarky 2015-03-29 09:09:17 +08:00
一般都是通过时间处理
|
5
Septembers 2015-03-29 09:25:15 +08:00 1
|
6
auser 2015-03-29 10:08:06 +08:00 via Android 1
c加加11 标准库自带 随机数生成器和分布
|
7
em70 2015-03-29 10:15:58 +08:00 via Android
取时间做余弦
|
8
zhicheng 2015-03-29 10:33:28 +08:00 via Android
/dev/urandom
|
9
jokester 2015-03-29 11:37:59 +08:00
单这个功能很难叫软件..叫程序比较好
|
10
mringg 2015-03-29 13:09:49 +08:00 via Android 1
伪随机数,貌似就一条语句就可以。如果是随机数就有点麻烦。
|
11
billlee 2015-03-29 13:45:29 +08:00
|
12
dacapoday 2015-03-29 14:58:26 +08:00
一种伪随机数,要验证随机程度,可以用随机数生成RGB颜色出图片,越像雪花无规律越随机
<code> uint32_t RandomSeed(void) { uint32_t ui32A, ui32B, ui32C, ui32D, ui32Temp, ui32Idx; // // Initialize the digest. // ui32A = 0x67452301; ui32B = 0xefcdab89; ui32C = 0x98badcfe; ui32D = 0x10325476; // // Perform the first round of operations. // #define F(a, b, c, d, k, s) \ { \ ui32Temp = a + (d ^ (b & (c ^ d))) + g_pui32RandomEntropy[k]; \ a = (ui32Temp << s) | (ui32Temp >> (32 - s)); \ } for(ui32Idx = 0; ui32Idx < 16; ui32Idx += 4) { F(ui32A, ui32B, ui32C, ui32D, ui32Idx + 0, 3); F(ui32D, ui32A, ui32B, ui32C, ui32Idx + 1, 7); F(ui32C, ui32D, ui32A, ui32B, ui32Idx + 2, 11); F(ui32B, ui32C, ui32D, ui32A, ui32Idx + 3, 19); } // // Perform the second round of operations. // #define G(a, b, c, d, k, s) \ { \ ui32Temp = (a + ((b & c) | (b & d) | (c & d)) + \ g_pui32RandomEntropy[k] + 0x5a827999); \ a = (ui32Temp << s) | (ui32Temp >> (32 - s)); \ } for(ui32Idx = 0; ui32Idx < 4; ui32Idx++) { G(ui32A, ui32B, ui32C, ui32D, ui32Idx + 0, 3); G(ui32D, ui32A, ui32B, ui32C, ui32Idx + 4, 5); G(ui32C, ui32D, ui32A, ui32B, ui32Idx + 8, 9); G(ui32B, ui32C, ui32D, ui32A, ui32Idx + 12, 13); } // // Perform the third round of operations. // #define H(a, b, c, d, k, s) \ { \ ui32Temp = a + (b ^ c ^ d) + g_pui32RandomEntropy[k] + 0x6ed9eba1; \ a = (ui32Temp << s) | (ui32Temp >> (32 - s)); \ } for(ui32Idx = 0; ui32Idx < 4; ui32Idx += 2) { H(ui32A, ui32B, ui32C, ui32D, ui32Idx + 0, 3); H(ui32D, ui32A, ui32B, ui32C, ui32Idx + 8, 9); H(ui32C, ui32D, ui32A, ui32B, ui32Idx + 4, 11); H(ui32B, ui32C, ui32D, ui32A, ui32Idx + 12, 15); if(ui32Idx == 2) { ui32Idx -= 3; } } // // Use the first word of the resulting digest as the random number seed. // return(ui32A + 0x67452301); } </code> |
15
dacapoday 2015-03-29 16:11:18 +08:00
@nbndco 所以是伪随机,毕竟有公式可循,我上面_转_的程序就是MD4,将顺序的数字,时间戳,变成乱码。只要不是用于加密,够用了。出图这方法确实是歪门邪道,但连图片都是充满水波纹或锯齿,就肯定不随机,出图只是直观了解一下而已
|
16
wanghanlin 2015-03-29 20:34:39 +08:00
|
17
jiashan 2015-03-29 20:35:10 +08:00
|
18
FifiLyu 2015-03-30 10:37:00 +08:00
伪随机数
#ifdef _WIN32 int64_t get_random() { LARGE_INTEGER large_interger_; QueryPerformanceCounter(&large_interger_); int64_t utime_ = large_interger_.QuadPart; return utime_; } #else /* 获取随机数 * 由于是根据时间(单位:纳秒)来生成,所以重复的几率非常小。 * 来源:linux until 中uuid源代码:gen_uuid.c */ int64_t get_random() { struct timeval tv; int32_t ret = 0; gettimeofday(&tv, 0); srand(tv.tv_sec ^ tv.tv_usec); /* Crank the random number generator a few times */ gettimeofday(&tv, 0); for (int32_t i = (tv.tv_sec ^ tv.tv_usec) & 0x1F; i > 0; i--) { ret = rand(); } return ret; } #endif |
19
yorTX9t 2015-03-30 22:50:20 +08:00
N 年前写的,可以生成六十几种伪随机数分布, C++: https://github.com/fengwang/random_variate_generator
|
20
liufuyi 2015-03-31 09:39:13 +08:00
这是要生成比特币私钥么?
|