Last active
October 9, 2016 02:16
-
-
Save LucasAlfare/9213521439e0704fe873db1beaab28cd to your computer and use it in GitHub Desktop.
ESBOÇO de gerador personalizado de números "aleatórios". Ta horrível, hahahah
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package testes; | |
/** | |
* Created by lucas on 08/10/16. | |
*/ | |
public class RandomPersonalizado { | |
public static long aleatorio(long limite){ | |
long r = 0; | |
while (true) { | |
r++; | |
if (condicao(getPowerByLimite((int) limite)) && r < limite){ | |
break; | |
} | |
} | |
return r; | |
} | |
public static long aleatorio(){ | |
long r = 0; | |
while (true) { | |
r++; | |
if (condicao()){ | |
break; | |
} | |
} | |
return r; | |
} | |
private static boolean condicao(int power){ | |
return (ultimos(System.nanoTime(), power)) == (ultimos(System.nanoTime(), power)); | |
} | |
private static boolean condicao(){ | |
return (ultimos(System.nanoTime(), 3)) == (ultimos(System.nanoTime(), 3)); | |
} | |
private static long ultimos(long target, int comprimento){ | |
String string = target + ""; | |
String aux = ""; | |
for (int i = 0; i < comprimento; i++){ | |
aux += string.charAt((string.length() - 1) - i); | |
} | |
return Long.parseLong(new StringBuilder(aux).reverse().toString()); | |
} | |
private static int getPowerByLimite(int limite){ | |
return (limite + "").length() - 1; | |
} | |
public static void main(String[] args) { | |
long curr = Long.MIN_VALUE; | |
for (int i = 0; i < 1; i++){ | |
long g = aleatorio(10); | |
if (curr < g) curr = g; | |
} | |
System.out.println(curr); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment