(rndseq[k] << 8) | (rand() & 0xff)
これらはそれが
rndseq[k] * 256 + rand() % 256
に変換することができる
(Cにおけるビット操作を参照)、バイナリ操作でありますコードの背後にあるアイデアは、ランダムなエントリで大きな配列を作成することですが、その方法は複雑すぎる
希望、これはあなたが論理を理解するのに役立ちます
//we want to fill this array with random numbers
static unsigned int rndseq[2048];
// for each k-entry of the array
for (k = 0; k < 2048; k++)
{
// initialize k-entry with zero
rndseq[k] = 0;
// for each byte in the k-entry integer
for (i=0; i < (int)sizeof(int); ++i)
//on the first iteration rndseq[k] is zero, so
//(rndseq[k] << 8) remains zero.
//(rand() & 0xff) creates a random number in the range [0,255]
//-> in the first iteration rndseq[k] will be set to a random number ([0,255])
//lets say, you have a int32 (4 bytes)
//you need 1 byte to represent 255
//so you have 3 "empty" bytes and 1 filled
//lets say, rand() got the number 1
//than rndseq would have the following value
//0x00-0x00-0x00-0x01
//in the next iteration you shift 1 byte, so
//you get from (rndseq[k] << 8)
//0x00-0x00-0x01-0x00
//the next random-number (still 1 byte) (lets say 2)
//will be stored in now free last byte
//result:
//0x00-0x00-0x01-0x02
//now you repeat, until all bytes are set
//result:
//0x01-0x02-0x03-0x04
rndseq[k] = (rndseq[k] << 8) | (rand() & 0xff);
}
thats CはC++ではありません。あなたは "bitshift"という単語を探しています。 – Hayt
これらの演算子はインターネットで簡単に検索できます。そのような質問をする必要はありません。 – cagatayodabasi
おお、私はあなたの品質を見ました。それ以上の議論は必要ありません。 – cagatayodabasi