Random
📘 Random Pool Selection Engine
This document defines the technical and functional logic of the Random Pool Selection engine,engine designed(RandomPoolServiceImp), to ensure total transparency and mathematical determinism in audit processes, validatedcovered by the RandomPoolServiceImpTest suite. Its goal is audit transparency: every number shown before a run can be traced back to a concrete rule below.
Last reviewed: 2026-12-01 — includes the Secondary Organization rule change (double random allowed).
1. Pool Universe (who can be selected)
A random always runs for the organization selected in the session, but its pool spans every organization that shares the same Group Random value. The pool is built in this order:
type = DOT, enabled = true) whose primary organization belongs to the group.
Rescued inactive employees, according to the RANDOM_POOL_INCLUDE_INACTIVE_EMPLOYEE parameter (see §3).
Secondary organization employees: active DOT employees whose secondary organization belongs to the group (see §2).
Each person enters the pool once. If someone is already in the pool by step 1 or 2, step 3 does not add them again.
The same eligibility service (IPersonEligibilityService) feeds the Distribution List, Preview and Run, so the list on screen and the pool used by the engine always contain the same people.
2. Secondary Organization Rule
⚠️ Rule changed (2026-12-01). The previous rule ("an employee is excluded from their primary organization if they have an active pool record in their secondary organization") no longer applies and was removed from the engine.
Current rule: double random is allowed.
TypeFormGroupRandom (Solo Drug / Solo Alcohol / ALL) to decide whether they are eligible for Drug, Alcohol or both — not the one of their primary organization.
In the summary, they are counted in the 2nd ORG column under the secondary organization's row.
Business context: used when the same employer has sub-companies per DOT mode (e.g., FMCSA + PHMSA). Before running a random, the admin can temporarily set a secondary organization on the employees that must be covered, and remove it afterwards. Because randoms often stay open for months while data is completed, overlaps between randoms are expected.
DOT multi-agency guidance generally suggests one pool per employee. Allowing double random was reviewed and accepted as a business decision.
Where it shows in the UI:
Secondary org · Primary: <primary org name> for people who entered by secondary organization. Empty for everyone else.
Activation headers (HUB popovers, services panel, Employee forms modal): show · Random from: <org> when the random that activated the test belongs to a different organization than the employee's form record.
HUB: changing Organization (Reg Mode) or Secondary Organization asks for confirmation (showing old → new value), because it changes which random pools the employee enters. The organizations offered as secondary are limited by the SHOW_SECONDARY_ORGANIZATION parameter.
3. Inactive Rescue Parameter
Parameter: RANDOM_POOL_INCLUDE_INACTIVE_EMPLOYEE (global, configured in the database).
| Value | Behavior |
|---|---|
| Empty / not configured | No inactive employee is rescued. |
true | All inactive DOT employees of the group are rescued. |
{COLUMN_CODE;VALUE} | Only employees whose custom column matches that value are rescued. Example: {EE_STATUS;L} (Leave of Absence). |
Inactive employees that are not rescued are reported in the IGNORED column.
4. Audit Transparency Structure (Preview)
The enginePreview generatesshows anone executionrow summaryper segmentedorganization intowith 6 key columns, each with a D|A (Drug | Alcohol) breakdown:
INCLUDE_INACTIVE_EMPLOYEERANDOM_POOL_INCLUDE_INACTIVE_EMPLOYEE ceil((Eligible + Inactive + 2nd Org) *× %) + Carry-Over. Carry-Over is added only if the organization's pool for that test is greater than 0. In fixed-quantity mode, see §8.
After a real Run, the results modal shows per organization: ONLY DRUG, ONLY ALC, BOTH and TOTAL selected.
5. Selection Logic
ALL or the matching Solo type).
Rounding: percentage draws use Math.ceil (round up). A fixed quantity larger
2.than Exclusionthe Logicpool &is Eligibility
capped Theat systemthe appliespool exclusion filters to prevent duplicate testing based on organization settings:
SecureRandom (RANDOM_SELECTION organization.universe=… Ifrequested=… noselected=…), TypeFormGroupRandom3.6. Carry-Over
Automatic (on Run): the engine takes the organization's most recent previous random (ordered by start date, any status, including CANCELED) and adds every test marked CARRY_OVER in it to the new random.
Manual Pull Carry-Over: from an existing random, the admin can pull carry-overs from another random of the same organization.
7. Data Integrity & Constraints
RandomPoolPerson included = false, so the random keeps evidence of the full universe it was drawn from.
Run parameters saved for audit: drug value, alcohol value and whether it was a percentage are stored on the random.
Name: RNDMPL-<ORG CODE>-<MMMdd>-<YYYY>.
Atomic run: the run is transactional; if any step fails, nothing is saved.
8. Known Limitations
ceil values can be slightly higher than the number actually drawn.
Fixed-quantity mode: each organization's TARGET shows the full fixed quantity, but the draw takes that quantity once for the whole group.
Inactive rescue parameter is global, not per organization.
Migration mode does not validate person IDs against the company or organization: the caller must make sure every ID belongs to 4.9. SecurityLifecycle
| Status | Meaning |
|---|---|
| **NEW** | Created by a Run. |
| **RUNNING** | Tests in progress. |
| **FINISHED** | Closed with the Finish button. Only allowed when every selected employee has completed their test. |
| **CANCELED** | Any non-finished random can be canceled; its incomplete tests are canceled too. |
10. Validations
The process will abortstops with a controlled error (no data saved) if:RuntimeException
| When | Condition | HTTP |
|---|---|---|
| Preview / Run | No stakeholder (service provider) assigned to the Random Pool test type for the organization. Checked first. | 409 |
| Preview / Run | Percentage mode with a Drug or Alcohol value outside 0–100. | 400 |
| Preview / Run | The | 409 |
| Finish | Some | 409 |
| Pull | Target | 409 |
| Run | Failure activating tests for the | 500 |
11. Migration Mode (historical load)
Migration mode loads into Nexus33 a random that was already drawn outside the system (e.g., historical randoms from before onboarding). It does not perform a draw: it records exactly the people provided.
Not available in the UI. It is triggered only through the Run endpoint with
migration = true, by the development/support team.
Input (Run request):
| Field | Meaning |
|---|---|
migration | true to enable the mode. |
distributionListIds | Comma-separated person IDs: the full universe of the historical random. Replaces the calculated pool. |
drugIds | Comma-separated person IDs selected for Drug. |
alcoholIds | Comma-separated person IDs selected for Alcohol. |
startDate / finishDate | Historical dates of the random. startDate is also used as the tests' activation date and in the random's name. |
Behavior:
drugIds / alcoholIds: no shuffle, no percentage, no TypeFormGroupRandom filter.
People in distributionListIds who are not in either list are saved with included = false, the same as a normal run.
The percentage = true, the values must be between 0 and 100.
Carry-over from the organization's previous random is still added (