Get somewhat random from a codeblock and avalanche
export function main() {
const now = new Date();
// Start with epoch ms
let x = now.getTime();
// Force to 32-bit signed int
x = x | 0;
// Xorshift32 mix (full)
x ^= x << 13;
x ^= x >>> 17;
x ^= x << 5;
// Optional extra avalanche
x = Math.imul(x, 0x85ebca6b);
x ^= x >>> 13;
x = Math.imul(x, 0xc2b2ae35);
x ^= x >>> 16;
const randomSeed = (x >>> 0) % 100 + 1;
return {
randomSeed,
timestamp: now.toISOString()
};
}
Make a variable of the timestamp

Use the random seed in the LLM prompt

You are selecting last-night sleep inputs for a mentor.
Inputs:
- Mentor Id: mentor.Mentor Id
- Age: mentor.Age
- Location: mentor.Location
- Current Mood: mentor.Current Mood
- Current Energy: mentor.Current Energy
Step 1 — Random seed:
RandomSeed:
Random Seed.randomSeed
Step 2 — Select SleepHours based on (2).randomSeed
- R ≤ 15 → {4.5, 5.5}
- 16–35 → {6.5}
- 36–65 → {7.5}
- 66–85 → {8.5}
- >85 → {9.0}
Step 3 — Select SleepQuality based on R and context:
- Start with baseline:
- R ≤ 30 → Poor
- 31–70 → OK
- >70 → Good
- Adjust one level down if:
- CurrentMood ∈ {Irritable, Restless, Wary}
- Adjust one level up if:
- CurrentEnergy < 25 AND Last24hSummary indicates exhaustion
- Clamp to {Poor, OK, Good}
Rules:
- Do not “optimize” for best sleep
- Variation is preferred over realism when plausible
- Avoid repeating the same SleepHours + SleepQuality as the previous night unless R ≤ 20
Output format (strict):
SleepHours:
SleepQuality:
SleepRationale:
Calculate
export function main() {
const now = new Date();
// Inputs (cast once)
const energyBefore = Math.min(
100,
Math.max(1, Number($mentorCurrentEnergyGetProperty) || 1)
);
const sleepHours = $useLlmSleepHoursGetStructField; // e.g. "9.0"
const sleepQuality = String($useLlmSleepQualityGetStructField); // "Poor" | "OK" | "Good"
// Base recovery by hours (string-keyed)
const baseRecoveryMap: Record<string, number> = {
"4.5": 15,
"5.5": 22,
"6.5": 30,
"7.5": 38,
"8.5": 45,
"9.0": 45
};
const qualityMultiplierMap: Record<string, number> = {
Poor: 0.6,
OK: 0.8,
Good: 1.0
};
const baseRecovery = baseRecoveryMap[sleepHours] ?? 0;
const multiplier = qualityMultiplierMap[sleepQuality] ?? 0.8;
const rawDelta = Math.round(baseRecovery * multiplier);
// Diminishing returns (prevents racing to 100)
const fatigueFactor = (100 - energyBefore) / 100;
const energyDelta = Math.max(1, Math.round(rawDelta * fatigueFactor));
const energyAfter = Math.min(100, energyBefore + energyDelta);
return {
energyBefore,
energyAfter,
sleepHours,
timestamp: now.toISOString()
};
}
Create the sleep log object

Update the main mentor record with the new energy value
