mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 04:37:48 +02:00
move randomBoolean and randomColorValue methods to SharedUtil
This commit is contained in:
parent
c7213d6593
commit
482e65c296
2 changed files with 33 additions and 3 deletions
|
@ -24,7 +24,16 @@ float randFloat () {
|
||||||
return (rand() % 10000)/10000.f;
|
return (rand() % 10000)/10000.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void outputBits(char byte) {
|
|
||||||
|
unsigned char randomColorValue(uint8_t miniumum) {
|
||||||
|
return miniumum + (rand() % (255 - miniumum));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool randomBoolean() {
|
||||||
|
return rand() % 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
void outputBits(unsigned char byte) {
|
||||||
printf("%d: ", byte);
|
printf("%d: ", byte);
|
||||||
|
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
|
@ -32,4 +41,19 @@ void outputBits(char byte) {
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int8_t numberOfOnes(unsigned char byte) {
|
||||||
|
return (byte >> 7)
|
||||||
|
+ ((byte >> 6) & 1)
|
||||||
|
+ ((byte >> 5) & 1)
|
||||||
|
+ ((byte >> 4) & 1)
|
||||||
|
+ ((byte >> 3) & 1)
|
||||||
|
+ ((byte >> 2) & 1)
|
||||||
|
+ ((byte >> 1) & 1)
|
||||||
|
+ (byte & 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool oneAtBit(unsigned char byte, int8_t bitIndex) {
|
||||||
|
return (byte >> (7 - bitIndex) & 1);
|
||||||
|
}
|
||||||
|
|
|
@ -19,7 +19,13 @@
|
||||||
|
|
||||||
double usecTimestamp(timeval *time);
|
double usecTimestamp(timeval *time);
|
||||||
double usecTimestampNow();
|
double usecTimestampNow();
|
||||||
|
|
||||||
float randFloat();
|
float randFloat();
|
||||||
void outputBits(char);
|
unsigned char randomColorValue(uint8_t minimum);
|
||||||
|
bool randomBoolean();
|
||||||
|
|
||||||
|
void outputBits(unsigned char byte);
|
||||||
|
int8_t numberOfOnes(unsigned char byte);
|
||||||
|
bool oneAtBit(unsigned char byte, int8_t bitIndex);
|
||||||
|
|
||||||
#endif /* defined(__hifi__SharedUtil__) */
|
#endif /* defined(__hifi__SharedUtil__) */
|
||||||
|
|
Loading…
Reference in a new issue