Skip to content

Instantly share code, notes, and snippets.

@sbstp
Created September 4, 2012 02:24
Show Gist options
  • Save sbstp/3615846 to your computer and use it in GitHub Desktop.
Save sbstp/3615846 to your computer and use it in GitHub Desktop.
int sommets = rand(8, 12);
int arretes = rand(sommets, 2 * (fact(sommets) / (fact(2) * fact(sommets - 2))));
GrapheOriente go = new GrapheOriente(sommets);
for (int i = 0; i < arretes; i++) {
int sommet1;
int sommet2;
do {
sommet1 = rand(1, sommets);
sommet2 = rand(1, sommets);
} while (sommet1 == sommet2 || go.sontAdjacents(sommet1, sommet2));
go.ajouterArrete(sommet1, sommet2);
}
// ...
private static int rand(int min, int max) {
return new Random(System.nanoTime()).nextInt(max - min) + min;
}
private static int fact(int num) {
return (num == 1) ? 1 : num * fact(num - 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment