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 |
|
Hi Ratah,
I have few comments
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 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
Best regards,
Honza
|
|
|
Goto Forum:
Current Time: Sat May 04 15:37:26 CEST 2024
Total time taken to generate the page: 0.02576 seconds
|