Jump to content

How would I be able to return a randomly generated number within a specific range?


12 posts in this topic

Recommended Posts

Posted

I'm thinking of updating the BTD Battles hack to have random numbers generated for the mediallions so the values aren't so big. People have caught on :p I would use MSHook of course.

 

Basically, I would want the range of the number to be from 100-10000. Thanks :)

Posted (edited)

So it would be like a random generated amount?

Yeah between a specific rangel

Updated by Guest
Posted (edited)

#include <stdlib.h>

//...
int r = arc4random_uniform(10000);

 

This would set it as a random number up to 10000.

Updated by Lethal
Posted

#include <stdlib.h>

//...

int r = arc4random_uniform(10000);

 

This would set it as a random number up to 10000.

I'll try tomarrow, thanks :)

Posted (edited)

I'll try tomarrow, thanks :)

 

<3 There is a method to set a minimum number but idk what it is. it's like 8 lines though.

Updated by Lethal
Posted (edited)

 

#include <stdlib.h>

...

int r = (rand() % 10000)+100;

This way it will always return values between 100 and 10000, this is the method without using the seed, I don't know how to use the seed in obj-c

Updated by DeathScripts
Posted (edited)

#include <stdlib.h>

//...

int r = arc4random_uniform(10000);

 

This would set it as a random number up to 10000.

Nice copy&paste ...

http://stackoverflow.com/questions/160890/generating-random-numbers-in-objective-c

 

 

But yes arc4random is the easiest way and doesn't need a seeder because it initializes itself

If you want a value from 100-10000 you would need

return arc4random() % 100) +10000;
Updated by castix

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...

Important Information

We would like to place cookies on your device to help make this website better. The website cannot give you the best user experience without cookies. You can accept or decline our cookies. You may also adjust your cookie settings. Privacy Policy - Guidelines