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

  • Home
  • SEARCH
  • 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 8298519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:48:25+00:00 2026-06-08T15:48:25+00:00

This is the code which I’m using a wrapper extension for a random class.

  • 0

This is the code which I’m using a wrapper extension for a random class.

public static class RandomHelper
{
    private static int currentSeed;
    private static Random rd = new Random();

    public static double Next()
    {
        return rd.NextDouble();
    }

    public static double Next(double min, double max)
    {
        return (rd.NextDouble() * (max - min)) + min;
    }

    public static double NextOnStep(double min, double max, double step)
    {
        int range = (int)Math.Floor((max - min) / step);
        int stepCount = rd.Next(0, range);
        return min + (step * stepCount);
    }

    public static double NextOnDecimalCount(double min, double max, int decimals)
    {
        double step = Math.Pow(10, decimals);
        return Math.Truncate(((rd.NextDouble() * (max - min)) + min) * step) / step;
    }

And imagine this situation, I have a class where contains three ranges of numbers

public class ArithmeticProblemGenerator()
{
    Range Number1Range {get;set;}
    Range Number2Range {get;set;}
    ...
    Range Number5Range {get;set;}
}

public class Range
{
    public Range()
    {
    }

    public Range(double min, double max)
    {
        this.Min = min;
        this.Max = max;
    }

    public double Min { get; set; }
    public double Max { get; set; }
}

And when I want to generate the problem, I add another method in my RandomHelper as extesion.

    #region RandomHelper extensions

    public static double Next(Range range)
    {
        return Next(range.Min, range.Max);
    }

    public static double NextOnStep(Range range, double step)
    {
        return NextOnStep(range.Min, range.Max, step);
    }

    public static double NextOnDecimalCount(Range range, int decimals)
    {
        return NextOnDecimalCount(range.Min, range.Max, decimals);
    }

    #endregion

But then I add a new feature of my ArithmeticProblemGenerator, I want to have numbers with different decimal places or sometimes the number follow a step.

So, I supposed, will it be good to create another two classes to add the following features.

public class RangeOnStep : Range
{
    public RangeOnStep()
    {
    }

    public RangeOnStep(double min, double max, double step)
        : base(min, max)
    {
        this.Step = step;
    }

    public double Step { get; set; }
}

public class RangeOnDecimalPlace : Range
{
    public RangeOnDecimalPlace()
    {
    }

    public RangeOnDecimalPlace(double min, double max, double decimalPlaces)
        : base(min, max)
    {
        this.DecimalPlaces = decimalPlaces;
    }

    public double DecimalPlaces { get; set; }
}

And add another method extensions with these new classes. Do you think I’m doing a good work or is a mess the design?

I wanna hear suggestions or opinions. Thanks in advance.

  • 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-06-08T15:48:26+00:00Added an answer on June 8, 2026 at 3:48 pm

    method extension isn’t usefull here, why not use a base class range and define overriden method like:

    public static class RandomHelper
    {
    private static int currentSeed;
    private static Random rd = new Random();

    public static double Next() 
    { 
        return rd.NextDouble(); 
    } 
    
    public static double Next(double min, double max) 
    { 
        return (rd.NextDouble() * (max - min)) + min; 
    } 
    
    public static double Next(RangeOnStep r) 
    { 
        int range = (int)Math.Floor((r.max - r.min) / r.step); 
        int stepCount = rd.Next(0, range); 
        return r.min + (step * stepCount); 
    } 
    
    public static double Next(RangeOnDecimalPlace r)) 
    { 
        double step = Math.Pow(10, r.decimals); 
        return Math.Truncate(((rd.NextDouble() * (r.max - r.min)) + r.min) * step) / step; 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is a small code which shows virtual methods. class A { public virtual
I have this code which does the trick: #include <stdio.h> int main() { int
I have this code (which is way simplified from the real code): public interface
I have this code which compiles and works as expected: class Right {}; class
I have this code in C++ which is giving weird output: #include<iostream> using namespace
I have this code which iterates through ArrayList<String> towns = new ArrayList<String>(); using JSTL
I have this code which builds an IList<string> : IList<string> databases; using (MySqlConnection _conn
i have this code which is not working. <jsp:useBean id=abbreviationlist class=AbbreviationListType/> <jsp:setProperty name=abbreviationlist property=id/>
i have this code which doesnt work: void CAnalyzerIF::SetData(int i_iIters, const CParameterSet* i_CParameterSet) {
Am trying to run a selenium suite using this code which runs perfectly on

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.