FlareStart
HomeNewsHow ToSources
FlareStart

Where developers start their day. All the tech news & tutorials that matter, in one place.

Quick Links

  • Home
  • News
  • Tutorials
  • Sources
  • Privacy Policy

Connect

© 2026 FlareStart. All rights reserved.

Back to articles
Building a Spin Wheel - Part 2, Weighted Randomness: Cumulative Method
How-ToWeb Development

Building a Spin Wheel - Part 2, Weighted Randomness: Cumulative Method

via Dev.to BeginnersDakshim Chhabra4h ago

In the last part, you have seen how we favored crypto.getRandomValues() than Math.random() . In this part, we'll be building a logic to provide us with weighted randomness using crypto.getRandomValues() , For this, I started my logic by using Uint8Array , but during research for a perfect algorithm, I came across a term known as aliasing . Though, I am still testing and researching on aliasing, but some discussions suggest that using low sample values while calculating the random value will impact the ability of the solution to be truly random. Therefore, I proceeded with using Uint32Array First, we'll be calculating a random value: const cryptoArray = new Uint32Array ( 1 ); window . crypto . getRandomValues ( cryptoArray ); const randomFloat = cryptoArray [ 0 ] / ( 2 ** 32 ); Here, for the sake of optimization, we can precalculate 2* 32 to be 4294967296 or create a constant that will hold the value of 2 *32. Second, let's define the items as an array of JSON: const slices = [ { id : 1

Continue reading on Dev.to Beginners

Opens in a new tab

Read Full Article
2 views

Related Articles

The Hidden Cost of Learning to Code Online
How-To

The Hidden Cost of Learning to Code Online

Medium Programming • 3h ago

How-To

How to File PIT-38 as an Interactive Brokers User in Poland — Without Losing Your Mind

Medium Programming • 3h ago

Most People Quit Programming Right Before This Happens
How-To

Most People Quit Programming Right Before This Happens

Medium Programming • 6h ago

Why Skill-Based Learning is Quietly Becoming the Real Standard of Education
How-To

Why Skill-Based Learning is Quietly Becoming the Real Standard of Education

Medium Programming • 6h ago

Context: a vital pattern nobody talks about
How-To

Context: a vital pattern nobody talks about

Medium Programming • 7h ago

Discover More Articles