float rstoc(x) { float decimal = abs(x - trunc(x)); float random_selector = (float)rand() / RAND_MAX; float adjustor; if (random_selector < decimal) adjustor = 1; else adjustor = 0; // consider sign if(x < 0) adjustor = -1 * adjustor; return trunc(x) + adjustor; }