Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » random functions proposal
Re: random functions proposal [message #35138 is a reply to message #35137] Mon, 16 January 2012 17:58 Go to previous messageGo to previous message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hi Ratah,

I have few comments Wink

First: I don't like the implementation of putBetween function. Cos() is too slow function to use for scaling. Also I admit I haven't really got the idea behind the scaling, as I was too lazy to think about it too much.

Second: Converting dword -> int using String is not a good idea Wink It will silence the compiler warnings, but still result into errors, because dword is unsigned 32 bit integer while int is signed 32bit integer (on most platforms), so the conversion will run into trouble when the dword is bigger then INT_MAX. Also the conversion through string is not efficient. In most cases you can probably just use simple cast: int(my_dword) and possibly check if the result is not negative.

Anyway short and simple solution to generate random number from given range is this:
int min=10;
int max=1000;
int rand = int(Random(max-min)+min); // you don't have to care about the range here as long as max < INT_MAX


I hope I haven't made any stupid mistake, as this all comes from the top of my head Smile

Best regards,
Honza
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Init a ctrl inside INITBLOCK
Next Topic: problem with new and delete
Goto Forum:
  


Current Time: Sat May 04 15:37:26 CEST 2024

Total time taken to generate the page: 0.02576 seconds