Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

how to generate random point

Dear community,

I' have written this function to generate random value at each iteration in a for loop, however, it seems that it doesn't do the expected job

  Point initPt(int nx0, int ny0, int nx1, int ny1){
    RNG rng;
    Point pt;
    double D = rng.uniform((double) nx0, (double) nx1);
    pt.x = round(D);

    D = rng.uniform((double) ny0, (double) ny1);
    pt.y = round(D);

    return pt;
}

I wrote this demo loop to see the results

    for (int i=0; i<n ; i++){
        Point pt = initPopulation(nx0, ny0, nx1, ny1);
        nest.at<int>(i,1) = pt.x;
        nest.at<int>(i,2) = pt.y;
        cout << pt <<endl;
    }

I got, unfortunately, this

   [127, 110]
   [127, 110]
   [127, 110]
   [127, 110]
   [127, 110]
   [127, 110]
   [127, 110]
   ...

I am glad to any help

how to generate random point

Dear community,

I' have written this function to generate random value at each iteration in a for loop, however, it seems that it doesn't do the expected job

  Point initPt(int nx0, int ny0, int nx1, int ny1){
    RNG rng;
    Point pt;
    double D = rng.uniform((double) nx0, (double) nx1);
    pt.x = round(D);

    D = rng.uniform((double) ny0, (double) ny1);
    pt.y = round(D);

    return pt;
}

I wrote this demo loop to see the results

    for (int i=0; i<n ; i++){
        Point pt = initPopulation(nx0, initPt(nx0, ny0, nx1, ny1);
        nest.at<int>(i,1) = pt.x;
        nest.at<int>(i,2) = pt.y;
        cout << pt <<endl;
    }

I got, unfortunately, this

   [127, 110]
   [127, 110]
   [127, 110]
   [127, 110]
   [127, 110]
   [127, 110]
   [127, 110]
   ...

I am glad to any help