Get random boolean in Java

后端 未结 10 1568
情深已故
情深已故 2020-12-01 11:28

Okay, I implemented this SO question to my code: Return True or False Randomly

But, I have strange behavior: I need to run ten instances simultaneously, where every

10条回答
  •  日久生厌
    2020-12-01 12:22

    you could get your clock() value and check if it is odd or even. I dont know if it is %50 of true

    And you can custom-create your random function:

    static double  s=System.nanoTime();//in the instantiating of main applet
    public static double randoom()
    {
    
    s=(double)(((555555555* s+ 444444)%100000)/(double)100000);
    
    
        return s;
    }
    

    numbers 55555.. and 444.. are the big numbers to get a wide range function please ignore that skype icon :D

提交回复
热议问题