How to generate random int (1 to 60)?

I’m been searching and it is not quite simple for me how to implement it

it seems I can’t rely if I want to build my game for android or win32 other than ios.

can somebody post how can I get random int(not float) between 1 to 60?

any tips are welcome, you don’t have to post the whole solution

thanks

2 Likes

there is cocos2d::RandomHelper::random_int(1, 60);

5 Likes

doing it thanks man

worked great, thanks for sharing your knoledge

hey what about using this statement : int x = arc4random() % 60 + 1;

which one is better…

import cstdlib

and then use rand()%60 +1 to give you numbers for the range 1 to 60

does cocos2d::RandomHelper::random_int(1, 60); suffer from modulo bias ?

If you want to generate random numbers, I think there are better ways: https://zuttobenkyou.wordpress.com/2012/10/18/generating-random-numbers-without-modulo-bias/

You can always look at the source code of the RandomHelper class and check :slight_smile:

1 Like