Type Safely

Type Safely

Share this post

Type Safely
Type Safely
Make a Random Number Generator That Works With Float, Double and Int
Copy link
Facebook
Email
Notes
More

Make a Random Number Generator That Works With Float, Double and Int

Daily Coding Tip 271

Type Safely's avatar
Type Safely
Mar 28, 2023
∙ Paid

Share this post

Type Safely
Type Safely
Make a Random Number Generator That Works With Float, Double and Int
Copy link
Facebook
Email
Notes
More
Share

white and blue round ornament
Photo by Alejandro Garay on Unsplash

I want to be able to generate a random float, double, or integer within a given range.

In order to do that, it helps to make NSNumber conform to the Comparable protocol. This makes it possible to decide whether one of these numbers is smaller, which will be useful later.

My NumberType enumeration has a range and a form…

Keep reading with a 7-day free trial

Subscribe to Type Safely to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2025 Type Safely
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share

Copy link
Facebook
Email
Notes
More