dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit c371c60d3e496891935c71bce70fde2707237cb0
parent 41230235b5175b6c0324ef7833b659c9d7797dce
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Thu,  1 Jun 2023 07:31:59 -0700

avoid generating the same number multiple time in a row

Diffstat:
Mpkg/odometer/odometer.go | 13++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/pkg/odometer/odometer.go b/pkg/odometer/odometer.go @@ -41,6 +41,7 @@ func (o *Odometer) Css() string { n := 20 step := 100.0 / float64(n) pct := 0.0 + var prev int for j := 0; j <= n; j++ { if j == n-(l-i) { break @@ -51,7 +52,17 @@ func (o *Odometer) Css() string { if j == 0 { pct += utils.RandFloat(0, 3) } - num := utils.RandInt(0, 9) + var num int + for { + num = utils.RandInt(0, 9) + if j > 0 { + if num == prev { + continue + } + } + break + } + prev = num out += fmt.Sprintf(`%.2f%% { content: "%d"; }`, pct, num) pct += step }