Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 223621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:14:19+00:00 2026-05-11T19:14:19+00:00

I have an interval consisting of two float numbers, and need to generate 20

  • 0

I have an interval consisting of two float numbers, and need to generate 20 random numbers in a look that are somewhere inbetween this interval defined by the two floats.

Lets say, for example:

float a = 12.49953f
float b = 39.11234f
float r = //best way to get best randomly numbers between a and b

The random number may be == a and == b. What would you suggest? I know that all computers and languages have problems with random numbers, and that there are many ways to generate them. But I have no experience in objective c.

It’s pretty important that the numbers that are generated are not the same in one block of 20 numbers that are generated in the loop. I think for that I would make a method, put the number in an array and check if the generated number differs from all others in the array, and if it doesnt, I would generate another one.

I’ve tried this:

CGFloat r = 1 + arc4random() % 5;

but that will only generate integers, and most of the time I get 2 times the same random number after another.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T19:14:19+00:00Added an answer on May 11, 2026 at 7:14 pm

    try this

    float a = 12.49953f;
    float b = 39.11234f;
    int startVal = a*10000;
    int endVal = b*10000; 
    
    srandom((unsigned)(mach_absolute_time() & 0xFFFFFFFF));
    int randomValue = startVal+ (random() % (endVal - startVal));
    
    float r = (float)randomValue / 10000.0f; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table in SQL Server consisting of two columns that track how
I have a time interval that spans years and I want all the time
I have a IEnumerable. I have a custom Interval class which just has two
If I have an instance of a System.Timers.Timer that has a long interval -
I have a loop that fades between images, with an interval set by the
I have a internal website that users log into. This data is saved as
I have a web app consisting of some JSPs that were previously running on
I have small project consisting of one maven project and two maven modules. One
I have a Windows Service consisting of a timer with 4000 Interval, in tick
I have a module that collects stats in an inconsistent time interval. Unfortunately, to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.