![]() |
| Forums | Gaming News | Videos | Downloads | Today's Posts | Mark Forums Read | Chat | FAQ | Members List | Contact |
| ||||||
This is a discussion on generating random nums?? within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; i know how to do this in lua but how do i do this in C?..?...
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 |
![]() likes kittens....awww....
Join Date: Sep 2006
Real First Name: Erik
Location: Detroit
Just Played: Call of Duty:World at War
Posts: 628
Trader Feedback: 0
|
i know how to do this in lua but how do i do this in C?..?
Last edited by psphacker12.; 09-30-2006 at 10:06 PM.. |
|
|
|
|
|
#6 |
![]() |
#include <stdlib.h>
i = rand(); Where: int i; is a pseudo-random number in the range 0 to RAND_MAX (where RAND_MAX is a manifest defined in <stdlib.h>). use
__________________
[IMG]http://img121.imageshack.us/img121/3852/untitled1copy7rf.png[/IMG] [IMG]http://img99.imageshack.us/img99/9711/newavatarjb9.gif[/IMG] [URL=http://forums.qj.net/showthread.php?t=9733][COLOR=DarkRed]Operation Positive Posting[/COLOR][/URL] [URL=http://forums.qj.net/showthread.php?t=49762][COLOR=Red]Guide to All Guides[/COLOR][/URL] [URL=http://forums.qj.net/showthread.php?t=13798][COLOR=Blue]Posting Guidelines[/COLOR][/URL] [URL=http://forums.qj.net/showthread.php?t=4394][COLOR=Green]Piracy Policy[/COLOR][/URL] [SIZE="3"][URL=http://forums.qj.net/f-general-psp-help-22/t-guide-opening-psp-disassembly-assembly-video-104303.html][COLOR=Red][B][U]PSP Disassembly Assembly Video Tutorial[/U][/B][/COLOR][/URL][/SIZE] |
|
|
|
|
|
#7 |
![]() ![]() ...in a dream...
|
Gahhh.... read the rules psphacker, search atleast a little bit... if all else fails, theres a thread for this, not to meantion its been answered many many times... Next youll probably ask how to create a random numbers between 2 values - start and end - which has been answered many times before in the help thread, as well as when searching google...
Putting in 'random number in C' gave me 118,000,000 using google...
__________________
...you'll never know what it's like... spending your whole life in a dream...
Launch a Kitten out of a Cannon and win real cash! Checkout my newly updated site for all my projects (Kitten Cannon, BOXHEAD, Light Cycle 3D) |
|
|
|
|
|
#8 |
![]() ![]() AKA Homer
|
In your main where you intialize everything call
srand(time(NULL)); Then when you want a random number call rand(); |
|
|
|
|
|
#9 |
![]() ![]() OMFG
|
I think he's looking for a more specific random number generator. Not some pseudo number.
Code:
#include <time.h>
srand(sceKernelLibcTime(NULL));
/* Get random number */
int getRandomNum(int min, int max)
{
int diff = max - min;
int res = (rand() % diff)+min;
return res;
}
|
|
|
|
|
|
#10 |
![]() ![]() Developer
|
rand() is pseudo anyway. The only 'random' factor used is the seed used with srand(). http://www.random.org/
|
|
|
|
|
|
#11 |
![]() ![]() OMFG
|
Last edited by Slasher; 10-01-2006 at 08:12 AM.. |
|
|
|
|
|
#13 | |
![]() ![]() Give It All
|
Quote:
__________________
Core 2 Duo E8400 @ 3.6ghz (Multiplier: 9x; Bus: 400mhz; FSB: 1600mhz;) GeForce 9800 GTX+ 512 MB (Core: 850mhz; Memory: 1200mhz; Shader: 2100mhz;) ASUS P5K Pro Motherboard Patriot Extreme (2x2GB) / OCZ HPC (2x1GB) 6GB Total Dual Channel RAM (DDR2 1066mhz) OCZ GameXstream 700w 2x Seagate 250GB HD (RAID0) |
|
|
|
|
|
|
#16 | |
![]() ![]() OMFG
|
Quote:
|
|
|
|
|
|
|
#17 |
![]() ![]() AKA Homer
|
That's why you seed it with time(NULL). The time is always increasing, so it should never be the same.
|
|
|
|
|
|
#18 | |
![]() ![]() SHOOP DA WHOOP
|
Quote:
|
|
|
|
|
|
|
#19 | |
![]() ![]() Give It All
|
Quote:
__________________
Core 2 Duo E8400 @ 3.6ghz (Multiplier: 9x; Bus: 400mhz; FSB: 1600mhz;) GeForce 9800 GTX+ 512 MB (Core: 850mhz; Memory: 1200mhz; Shader: 2100mhz;) ASUS P5K Pro Motherboard Patriot Extreme (2x2GB) / OCZ HPC (2x1GB) 6GB Total Dual Channel RAM (DDR2 1066mhz) OCZ GameXstream 700w 2x Seagate 250GB HD (RAID0) |
|
|
|
|
|
|
#21 |
![]() |
You can also specify the limit.
See.... Just use simple rand() function. Code:
..
....
.....
int main(void)
{
pspDebugScreenInit();
SetupCallbacks();
int rn; //random number holder
rn=rand()%100;//Where rand generates a random number inside 100;
pspDebugScreenPrintf("Generated Integer:%d",rn);
sceKernelSleepThread();
return 1;
}
|
|
|
|
|
|
#22 |
![]() ![]() ...in a dream...
|
Dont you think it'd be best to make the seed sceKernelLibcClock(void );? that returns the # of miliseconds since hte app has started... Seems better than time being seconds...
__________________
...you'll never know what it's like... spending your whole life in a dream...
Launch a Kitten out of a Cannon and win real cash! Checkout my newly updated site for all my projects (Kitten Cannon, BOXHEAD, Light Cycle 3D) |
|
|
|
|
|
#23 |
![]() ![]() ![]() Developer
|
http://www.psp-programming.com/dev-f...pic.php?t=1076
Make sure to look at the last post if you want it to work right...
__________________
For game downloads and development updates, check out my website. http://xfacter.wordpress.com/ |
|
|
|
|
|
#24 |
![]() ![]() ...in a dream...
|
Ok, the truth ehind rand():
Code:
static unsigned long _seed = 0;
long
rand(void)
{
if (_seed == 0)
_seed = 1;
if ((((_seed << 3) ^ _seed) & 0x80000000L) != 0)
_seed = (_seed << 1) | 1;
else
_seed <<= 1;
return _seed - 1;
}
void
srand(unsigned long new_seed)
{
_seed = new_seed;
}
__________________
...you'll never know what it's like... spending your whole life in a dream...
Launch a Kitten out of a Cannon and win real cash! Checkout my newly updated site for all my projects (Kitten Cannon, BOXHEAD, Light Cycle 3D) |
|
|
|
|
|
#26 | |
![]() ![]() Bush Programmer
|
Quote:
are connected. It would be influenced by EMI from the environment, so not truly random, but the best seed for random numbers on the PSP so far. You can see the noise by starting this app: http://home.arcor.de/themirek/pspdev/audioinput.zip Press Circle and then square. You don't need to bother plugging a mic or remote in. |
|
|
|
|
![]() |
| Tags |
| generating , nums , random |
| Thread Tools | |
|
|