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
/** | |
* | |
* @param objects: A Map containing the objects to choose from, where the keys represent the objects and the values represent their respective weights. | |
* @return Returns a randomly selected element from a Map, with selection probabilities proportional to each element's weight. | |
* @param <T> A randomly selected element from the Map, or null if the Map is empty. | |
*/ | |
public static <T> T getRandomWeightedElement(Map<T, Number> objects) { | |
double sum = objects.values().stream().mapToDouble(Number::doubleValue).sum(); | |
for (T item : objects.keySet()) { | |
random -= objects.get(item).doubleValue(); |
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
#include <cstdint> | |
#include <string> | |
#include <sstream> | |
#include <iomanip> | |
uint32_t rotateLeft(uint32_t x, uint32_t n) { | |
return (x << n) | (x >> (32 - n)); | |
} | |
std::string sha256(const std::string& input) { |
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
// | |
// Created by kotlinsyntax on 6/7/2024. | |
// | |
#ifndef ARRAY_HPP | |
#define ARRAY_HPP | |
#include <cstdarg> | |
#include <cstdio> | |
#include <cstring> | |
#include <functional> |