From 065227c985a1b4abf1b4c9a1abc57db5f1dcc22b Mon Sep 17 00:00:00 2001 From: Julien Calixte Date: Mon, 31 Jul 2023 18:07:10 +0200 Subject: [PATCH] use a true randomness in the app --- core.css | 3 +-- src/modules/article/FlowSetup.vue | 3 ++- src/modules/feature/feature-board.ts | 5 +++-- src/modules/feature/feature.fixture.ts | 3 ++- src/utils.ts | 16 ++++++++++++++-- 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/core.css b/core.css index cc6f984..2fc9033 100644 --- a/core.css +++ b/core.css @@ -32,9 +32,8 @@ main { .meaning { color: #9f9a9a; - font-style: italic; font-weight: 100; - font-size: 1.2rem; + font-size: 1rem; } .meaning::before { diff --git a/src/modules/article/FlowSetup.vue b/src/modules/article/FlowSetup.vue index b95ecea..e66eeec 100644 --- a/src/modules/article/FlowSetup.vue +++ b/src/modules/article/FlowSetup.vue @@ -91,7 +91,8 @@ const feature: Feature = { Blue bins are your security stock, to make sure teams can work without any blockers. It's to make sure the next team will always have material to transform. But it comes with a cost: overburden, stagnation (increase lead - time) and duplicated mistakes (not simulated here). The less you have, the + time) and duplicated mistakes + not simulated here. The less you have, the less your team has mental charge. The more you have, the more secure you are to make teams work. One solution: simplify your flow and lower the number of operation the teams have to do to deliver a feature. diff --git a/src/modules/feature/feature-board.ts b/src/modules/feature/feature-board.ts index 5554241..c5f57b7 100644 --- a/src/modules/feature/feature-board.ts +++ b/src/modules/feature/feature-board.ts @@ -7,6 +7,7 @@ import { getMean, pickRandomElement, popNElement, + randomFloat, shuffleArray, sumElements } from '@/utils' @@ -28,7 +29,7 @@ const hasQualityIssue = ({ ) const multiplicator = getOverburdenMultiplicator(tasksInParallel) - const quality = Math.random() + const quality = randomFloat(0, 1) return quality > qualityProbability / multiplicator } @@ -230,7 +231,7 @@ export const nextDay = ( state.meta.teamWorkExperience += 0.01 if (strategy === 'problem-solving') { - const hasTeamLearned = Math.random() > 0.25 + const hasTeamLearned = randomFloat(0, 1) > 0.25 if (hasTeamLearned) { state.meta.teamWorkExperience += 1.2 } diff --git a/src/modules/feature/feature.fixture.ts b/src/modules/feature/feature.fixture.ts index 051c2f5..fa07fbf 100644 --- a/src/modules/feature/feature.fixture.ts +++ b/src/modules/feature/feature.fixture.ts @@ -1,9 +1,10 @@ import { birds } from '@/data/bird' import { Feature } from '@/modules/feature/feature' +import { randomInteger } from '@/utils' export const features: Feature[] = birds.map((name) => ({ name, - complexity: Math.floor(Math.random() * 5) + 1, + complexity: randomInteger(1, 5), leadTime: 0, status: 'doing', step: Infinity, diff --git a/src/utils.ts b/src/utils.ts index a830c65..b6a43e8 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,3 +1,15 @@ +import { Random } from 'random-js' + +const random = new Random() + +export const randomInteger = (min: number, max: number) => { + return random.integer(min, max) +} + +export const randomFloat = (min: number, max: number) => { + return random.real(min, max) +} + export const getMean = (data: number[]) => Math.round(100 * (sumElements(data) / data.length)) / 100 @@ -11,7 +23,7 @@ export const shuffleArray = (array: T[]) => { randomIndex while (currentIndex !== 0) { - randomIndex = Math.floor(Math.random() * currentIndex) + randomIndex = randomInteger(0, currentIndex - 1) currentIndex-- ;[array[currentIndex], array[randomIndex]] = [ array[randomIndex], @@ -37,7 +49,7 @@ export const popNElement = (array: T[], numberOfElements: number) => { } export const pickRandomIndex = (array: T[]) => - Math.floor(Math.random() * array.length) + randomInteger(0, array.length - 1) export const pickRandomElement = (array: T[]) => array[pickRandomIndex(array)]