Freigeben über


seed_seq::generate

Generates a randomized interval from the seeds.

template<class RandomAccessIterator>
    void generate(
        RandomAccessIterator first,
        RandomAccessIterator last
    ) const;

Parameters

  • first
    A random access iterator addressing the position of the first element in the source range.

  • last
    An random access iterator addressing the position of the last element in the source range.

Remarks

The template function initializes the elements of the sequence [first, last) (if the sequence is non-empty) as follows:

const size_t s = vec.size();
const size_t n = last - first;
const size_t t = 623 <= n ? 11 : 68 <= n ? 7
    : 39 <= n ? 5 : 7 <= n ? 3 : (n - 1) / 2;
const size_t p = (n - t) / 2;
const size_t q = p + t;
const size_t m = n <= s ? s + 1 : n;
size_t k;

for (k = 0; k < n; ++k)
    first[k] = 0x8b8b8b8b;

for (k = 0; k < m; ++k)
    {    // scramble and add any vector contribution
    result_type r1 = 1664525
        * xor27(first[k % n] ^ first[(k + p) % n] ^ first[(k - 1) % n]);
    result_type r2 = r1
        + (k == 0 ? s : k <= s ? k % n + vec[k - 1] : k % n);

    first[(k + p) % n] += r1;
    first[(k + q) % n] += r2;
    first[k] = r2;
    }

for (; k < m + n; ++k)
    {    // rescramble
    result_type r3 = 1566083941
        * xor27(first[k % n] + first[(k + p) % n] + first[(k - 1) % n]);
    result_type r4 = r3 - k % n;

    first[(k + p) % n] ^= r3;
    first[(k + q) % n] ^= r4;
    first[k] = r4;
    }

The function xor27 is defined as:

result_type xor27(result_type val) const
    {    // shift and merge
    return (val ^ (val >> 27));
    }

Requirements

Header: <random>

Namespace: std

See Also

Reference

<random>

seed_seq Class

Other Resources

<random> Members