Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
There's no requirement that hash values be consistent between different Java implementations, or even between different execution runs of the same program, and while two unequal objects having different hashes is very desirable, this is not mandatory (that is, the hash function implemented need not be a perfect
A perfect hash function for a specific set S that can be evaluated in constant time, and with values in a small range, can be found by a randomized algorithm in a number of operations that is proportional to the size of S
If two objects are equal according to the {code equals(Object)} method, then calling the {code hashCode} method on each of the two objects must produce the same integer result.
Ну раз вы такой умный, киньте кусочек исходного кода из пакета java.lang, где используется Random в hashCode().Отвечу в поддержку SSSurkv:
template <class T> void QuickSort(T x[], long a, long b, bool (*f)(T,T))
{
long i = a, j = b;
T temp, p = x[b/2]; //выбираем граничный элемент - середину
//p = x[i]; //выбираем первый элемент (5000000 эл. за 1980 мс)
//p = x[i+rand()%N-i]; //выбираем случайный элемент (5000000 эл. за 2120 мс)
do {
while ( f(x[i],p) ) ++i;
while ( f(p,x[j]) ) --j;
if (i <= j) { temp = x[i]; x[i++] = x[j]; x[j--] = temp; }
} while (i <= j);
if( j > 0 ) QuickSort(x, a, j, f);
if( b > i ) QuickSort(x+i, a, b-i, f);
}
But does it work? Ironically, the answer is yes — but probably not for the reason that the developer intended to solve. In our tests Chrome was snappier and Google Maps was much quicker drawing tiles. Why? Probably not because the entropy pool was any quicker, but because the CPU and I/O processes were being “kept hot” by the app constantly updating the system with the new, “less random” bits. In short, the CPU wasn’t returning to a slower speed as frequently, resulting in a faster experience — and shorter battery life.
CyanogenMod maintainer chimed in:
“IMNSHO the recent entropy pool fad is bull***. The only users of /dev/random are libcrypto (used for cryptographic operations like SSL connections, ssh key generation, and so on), wpa_supplicant/hostapd (to generate WEP/WPA keys while in AP mode), and the libraries that generate random partition IDs when you do an ext2/3/4 format. None of those 3 users are in the path of app execution, so feeding random from urandom does nothing except make random… well… less random.
“The only conceivable reason some devices may feel faster is because by constantly polling the PRNG, it keeps the device’s I/O in constant use (which in turn, depending on device, will make the CPU stick to higher clock frequencies to keep up and/or ramp up the IO scheduler).”
One thing you should not do is the following:
rngd -r /dev/urandom
i = (i + 1) % MAXI
получают ещё один быстрый алгоритмический генератор псевдослучайности
с пропатченных таким образом андроидов гораздо менее секьюрно пользоваться тем же https
dd if=/dev/random of=/dev/null bs=128 count=11
при первом вызове выдала 85 байт в секунду, передала 481 байт за 5,628 секунд. Следующие вызовы уже показывали скорость 12 байт в секунду.dd if=/dev/random of=/dev/null bs=1 count=2000
dd if=/dev/random of=/dev/null bs=26 count=16
5+11 records in 5+11 records out 238 bytes transferred in 3.228 secs (73 bytes/sec)
16+0 records in 416 bytes transferred
11+5 records in 326 bytes transferred in 3.469 secs (93 bytes/sec)
8+8 records in 284 bytes transferred in 4.495 secs (63 bytes/sec)
5+11 records in 223 bytes transferred in 6.038 secs (36 bytes/sec)
1+15 records in 163 bytes transferred in 9.562 secs (17 bytes/sec)
# dd if=/dev/random of=/dev/null bs=26 count=16 0+16 records in 0+16 records out 140 bytes transferred in 7.447 secs (18 bytes/sec)
watch -n 1 cat /proc/sys/kernel/random/entropy_avail
стабильно показывала значения из диапазона 120-140.Since reads from /dev/random may block, users will usu‐
ally want to open it in nonblocking mode (or perform a read with
timeout), and provide some sort of user notification if the
desired entropy is not immediately available.
В старых версиях Android некоторые системные компоненты и JVM активно...Теперь некоторые моменты:
— Упомянутые многими комментирующими разработчики андроида могут идти лесом, т.к. к труппе xda-developers у меня гораздо больше доверия — они по крайней мере используют и поддерживают старые устройства.
Вообще, словосочетание «гаражный сервис» как то не совсем укладывается в одно предложение с open source, вам не кажется? Тот же линукс возьмите…
Генератор энтропии Seeder 1.1 существенно уменьшает лаги на Android-устройствах