Skip to content

Commit c5bfb00

Browse files
committed
PointDistribution : Avoid std::random_shuffle()
This was deprecated in C++14 and removed in C++17.
1 parent 626e9cf commit c5bfb00

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

src/IECore/PointDistribution.cpp

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,31 @@ PointDistribution::PointDistribution( const std::string &tileSet )
8585
// choosing which tile to use at the top level.
8686
//////////////////////////////////////////////////////////////////////////////////////
8787

88-
m_perm.resize( m_permSize * 2 );
88+
// This was originally generated using `std::random_shuffle`, which did not yield the
89+
// same results on different platforms and which was removed in C++17. The results here
90+
// were generated on Linux with `libstdc++`, maintaining compatibility with the majority
91+
// of previous usage.
92+
93+
m_perm = { 147, 228, 196, 166, 243, 130, 108, 90, 46, 3, 162, 12, 221, 180, 56, 194, 77,
94+
84, 241, 8, 175, 250, 224, 34, 44, 246, 40, 23, 103, 26, 106, 212, 189, 98, 30, 114,
95+
135, 80, 21, 136, 187, 208, 184, 144, 171, 64, 201, 74, 131, 13, 170, 14, 254, 214,
96+
62, 31, 94, 51, 16, 240, 186, 104, 193, 53, 235, 82, 4, 158, 203, 120, 225, 110, 245,
97+
59, 101, 102, 54, 206, 93, 70, 33, 69, 88, 41, 251, 24, 49, 142, 139, 43, 249, 52, 220,
98+
7, 237, 79, 173, 71, 164, 83, 146, 17, 178, 218, 226, 86, 132, 87, 112, 160, 29, 85,
99+
163, 65, 19, 126, 255, 42, 138, 67, 47, 238, 128, 75, 37, 72, 153, 192, 11, 123, 6,
100+
129, 183, 113, 197, 252, 222, 127, 157, 152, 213, 81, 39, 97, 60, 174, 105, 73, 143,
101+
91, 61, 216, 116, 154, 205, 188, 134, 150, 177, 115, 195, 35, 229, 210, 122, 27, 2,
102+
76, 5, 148, 141, 89, 247, 99, 121, 230, 219, 204, 200, 172, 231, 117, 140, 167, 227,
103+
156, 253, 181, 236, 232, 209, 9, 45, 100, 78, 161, 22, 63, 179, 1, 25, 248, 182, 198,
104+
50, 111, 57, 151, 15, 107, 66, 48, 217, 211, 176, 159, 137, 58, 18, 32, 199, 165, 36,
105+
95, 68, 185, 10, 202, 242, 92, 190, 191, 149, 234, 55, 38, 119, 133, 20, 223, 124, 118,
106+
244, 155, 0, 233, 168, 169, 109, 145, 28, 215, 125, 96, 239, 207
107+
};
108+
109+
assert( m_perm.size() == m_permSize );
89110

90-
// fill first half with the values 0-m_permSize
91-
unsigned int value=0;
92-
std::vector<unsigned int>::iterator it = m_perm.begin();
93-
while (it != m_perm.begin()+m_permSize)
94-
{
95-
*it++ = value++;
96-
}
97-
ImathRandAdapter<Imath::Rand32> random( 101 );
98-
std::random_shuffle( m_perm.begin(), m_perm.begin() + m_permSize, random );
99111
// fill second half of table with a copy of first half
112+
m_perm.resize( m_permSize * 2 );
100113
std::copy( m_perm.begin(), m_perm.begin() + m_permSize, m_perm.begin() + m_permSize );
101114

102115
}

0 commit comments

Comments
 (0)