Created
July 6, 2025 21:18
-
-
Save Platin21/d937ee499b41dedb0d634cee490c2b8f to your computer and use it in GitHub Desktop.
Value Distribution Function
This file contains hidden or 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
| /* Lic: All rights reserved Platin21 */ | |
| #include <stlib.h> | |
| float* distribution(float minimum_value, float maximum_value, float sum, int count_of_values, float* values, float* total) { | |
| float summe_min_wert = minimum_value * count_of_values; | |
| float left_over_sum = sum - summe_min_wert; | |
| float sum_of_random_distribution = 0.0f; | |
| for (int i = 0; i < count_of_values; i++) { | |
| values[i] = (float)rand() / maximum_value; | |
| sum_of_random_distribution += values[i]; | |
| } | |
| float temp_total = 0; | |
| for (int i = 0; i < count_of_values; i++) { | |
| float single_entry = values[i] / sum_of_random_distribution; | |
| values[i] = minimum_value + single_entry * left_over_sum; | |
| temp_total += values[i]; | |
| } | |
| if(total != nullptr) { | |
| *total = temp_total; | |
| } | |
| return values; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment