T[256];f(x){srand(x&&f(x-1));for(;T[x=rand()%256]++;);return x;}
输入范围为[0 255]的输入。
在线尝试!—在TIO(使用GCC)上,将产生:
103,198,105,115,081,255,074,236,041,205,186,171,242,251,227,070,
124,194,084,248,027,232,231,141,118,090,046,099,051,159,201,154,
102,050,013,183,049,088,163,037,093,005,023,233,094,212,178,155,
180,017,014,130,116,065,033,061,220,135,112,062,161,225,252,001,
126,151,234,107,150,143,056,092,042,176,059,175,060,024,219,002,
026,254,067,250,170,058,209,230,148,117,216,190,097,137,249,187,
168,153,015,149,177,235,241,179,239,247,000,229,202,011,203,208,
072,071,100,189,031,035,030,028,123,197,020,075,121,036,158,009,
172,016,080,021,111,034,025,125,245,127,164,019,181,078,152,224,
077,052,188,095,119,108,134,043,085,162,004,211,054,226,240,228,
079,073,253,169,008,138,010,213,068,091,243,142,076,215,045,066,
006,196,132,173,222,048,246,032,133,007,244,185,195,217,160,120,
218,106,083,144,087,238,207,096,210,053,101,063,098,128,165,089,
140,012,192,131,047,039,022,147,184,109,182,193,199,237,018,069,
057,157,174,104,122,166,055,110,003,040,139,086,145,114,129,113,
206,167,191,214,146,221,136,038,156,082,200,029,044,204,223,064
请注意,在其他系统上,由于C没有强制rand
执行特定的实现,因此它可能会产生不同的(但仍然有效)输出。我提交的内容专门是在TIO上运行的版本(链接)。
对于我无法获得像我的原始(f(x){return rand(srand(x*229))/229%256;}
)版本可以在TIO上使用的版本,我感到非常失望,因为我认为这要优雅得多。由于这仅适用于在OS X上运行的Clang,因此在竞争中不公平。这个人仍然很难扭转,所以我猜就足够了。