From 6d865d476289640dbeacc8551d3e66bd7686bb8a Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Mon, 27 Mar 2006 21:55:34 +0000 Subject: [PATCH] fix RandomGen off by 1. Was retruning.[0,max), not [0,max]. (Caused random courseEntries to never pick the last song in the list) --- stepmania/src/RageUtil.cpp | 5 ++++- stepmania/src/RageUtil.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/stepmania/src/RageUtil.cpp b/stepmania/src/RageUtil.cpp index 9db4118640..ea16a8bcb4 100644 --- a/stepmania/src/RageUtil.cpp +++ b/stepmania/src/RageUtil.cpp @@ -48,7 +48,10 @@ RandomGen::RandomGen( unsigned long seed_ ) int RandomGen::operator() ( int maximum ) { - return int(RandomFloat( seed ) * maximum); + float f = RandomFloat(seed) * (maximum+1); + int ans = int(f); + CLAMP( ans, 0, maximum ); + return ans; } diff --git a/stepmania/src/RageUtil.h b/stepmania/src/RageUtil.h index e9eb22a512..1da17f4837 100644 --- a/stepmania/src/RageUtil.h +++ b/stepmania/src/RageUtil.h @@ -160,7 +160,7 @@ inline uint16_t Swap16LE( uint16_t n ) { return Swap16( n ); } extern int randseed; -float RandomFloat( int &seed ); +float RandomFloat( int &seed ); // between 0.0f and 1.0f inline float RandomFloat() {