Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
Expand all | Collapse all

random float range

  • 1.  random float range

    Posted Wed January 03, 2018 06:58 PM

    Originally posted by: vahid_mlkr


    Hi

    Anyone know how can I generate random float numbers within specific ranges  of (e.g 1.7 to 3.5) in cplex java ?

    I can see that there is a class rand(), but it only takes integers and also it is not possible to define the minimum and maximum range for that

    Thank you


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: random float range

    Posted Thu January 04, 2018 02:11 AM

    Hi,

    let me show you how to turn rand into what you need:

    // 1.7 to 3.5

    float m=1.7;
    float M=3.5;

    int scale=1000000;

    float randomFloat=m+1/scale*(rand(scale+1))*(M-m);
    float randomFloats[i in 1..100]=m+1/scale*(rand(scale+1))*(M-m);

    execute
    {
    writeln("randomFloat = ",randomFloat);
    randomFloats;
    }

    assert forall(i in 1..100) as1:m<=randomFloats[i];
    assert forall(i in 1..100) as2:randomFloats[i]<=M;

    regards


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: random float range

    Posted Thu January 04, 2018 11:21 AM

    Originally posted by: vahid_mlkr


    Thank you so much for your great help


    #CPLEXOptimizers
    #DecisionOptimization