samedi 30 janvier 2016

Generate a non random value between two integers

I'd want to know how to get return a int between to others and always be the same, not random. I've coded this:

 public static int getIndex(int a, int b)
    {
        if (a > b+b || a == b) return b / 2;
        else if ((a + b / 2) > b) return (a + b) / 4;
        else return (a + b) / 2;
    }

Is there a better way to do this?




Aucun commentaire:

Enregistrer un commentaire