libH/UtilMath.cpp

Go to the documentation of this file.
00001 
00012 /*
00013   
00014   Copyright (c) 2007, Tim Burrell
00015   Licensed under the Apache License, Version 2.0 (the "License");
00016   you may not use this file except in compliance with the License.
00017   You may obtain a copy of the License at 
00018 
00019         http://www.apache.org/licenses/LICENSE-2.0
00020 
00021   Unless required by applicable law or agreed to in writing, software
00022   distributed under the License is distributed on an "AS IS" BASIS,
00023   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00024   See the License for the specific language governing permissions and 
00025   limitations under the License. 
00026   
00027 */
00028 
00029 #include "UtilMath.hpp"
00030 #include "../libH/Debug.hpp"
00031 #include <sys/time.h>
00032 #include <math.h>
00033 
00034 using namespace H;
00035 
00037 // Defines / Type Defs
00039 
00041 // Construction
00043 
00047 UtilMath::UtilMath() {
00048 }
00049 
00053 UtilMath::~UtilMath() {
00054 }
00055 
00057 // Class Body
00059 
00064 int UtilMath::intDivRoundUp(int Div1, int Div2) {
00065         return (int) ceil((double)Div1/(double)Div2);
00066 }
00067 
00072 float UtilMath::random() {
00073         return rand() / (float) RAND_MAX;
00074 }
00075 
00080 void UtilMath::randomize() {
00081         srand((unsigned)time(NULL));
00082 }
00083 
00088 float UtilMath::randomFloat(float MinVal, float MaxVal) {
00089         float Rnd = random();
00090         float Range = MaxVal - MinVal;
00091         float Ans = Range * Rnd;
00092 
00093         return Ans + MinVal;
00094 }
00095 
00100 int UtilMath::randomInt(int MinVal, int MaxVal) {
00101         float Rnd = random();
00102         float Range = MaxVal - MinVal;
00103         float Ans = Range * Rnd;
00104 
00105         return (int) (Ans + MinVal);
00106 }

Generated on Wed Nov 7 10:04:16 2007 for gizmod by  doxygen 1.5.3