this function will return a random free index in a max (bit must be 0) if there are none, then return a random index??
| 1363 | // this function will return a random free index in a max (bit must be 0) |
| 1364 | // if there are none, then return a random index?? |
| 1365 | inline int FIND_FREE_INDEX(unsigned mask, unsigned max_items, bool allow_duplicates) { |
| 1366 | int i; |
| 1367 | int8_t indices[32]; |
| 1368 | int8_t nindices = 0; |
| 1369 | |
| 1370 | for (i = 0; i < max_items; i++) { |
| 1371 | if ((mask & (1 << i)) == 0) { |
| 1372 | indices[nindices++] = i; |
| 1373 | } |
| 1374 | } |
| 1375 | |
| 1376 | if (nindices == 0) { |
| 1377 | if (allow_duplicates) { |
| 1378 | return (rand() % max_items); |
| 1379 | } else { |
| 1380 | return -1; |
| 1381 | } |
| 1382 | } else { |
| 1383 | return (int)(indices[rand() % nindices]); |
| 1384 | } |
| 1385 | } |
| 1386 | |
| 1387 | /* |
| 1388 | $$ACTION |
no outgoing calls
no test coverage detected