generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: C++ pseudo random code?

Previous Thread :: Next Thread 
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
17 Feb 2012 05:21 PM
Can you explain this to me? I looked at it in the C++ wiki, but I didn't understand. Can someone help explain it to me please?
Report Abuse
myrkos is not online. myrkos
Joined: 06 Sep 2010
Total Posts: 8072
17 Feb 2012 05:24 PM
It's probably referring to a pseudo-random generator. This is a generator that tries to generate completely random numbers, but they're technically not random because they're still based on some predictable algorithm, thus they're called pseudo-random.
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
17 Feb 2012 05:39 PM
I know. But I didn't understand it. I didn't understand the library, how the code it, can you explain please?
Report Abuse
swmaniac is not online. swmaniac
Joined: 28 Jun 2008
Total Posts: 15773
17 Feb 2012 07:09 PM
Post the code.
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
17 Feb 2012 09:28 PM
#include < stdafx.h > // I don't get this library.
#include < iostream >
using namespace std;
unsigned int PRNG()
{
static unsigned int nSeed = 5323;
nSeed = (8253729 * nSeed + 2396403);
return nSeed % 32767; }
int main() {
for (int nCount=0; nCount < 100; ++nCount)
{ cout << PRNG() << "\t";
if ((nCount+1) % 5 == 0)
cout << endl; } }

Sorry it's kinda bad writin. I had to copy and paste. But can you explain this to me? Especially that library stdafx.h.
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
17 Feb 2012 09:30 PM
stdafx.h is an essential library, it's basically like the System32 of C++.
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
17 Feb 2012 09:32 PM
Explain more please...
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
17 Feb 2012 09:34 PM
There's nothing more to explain. It should be clear enough.
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
17 Feb 2012 09:36 PM
Can you explain system32.

And can you write a pseudo code and ask you questions about that? Because the wiki one I didn't get.
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
17 Feb 2012 09:38 PM
Uhh...

Shouldn't that PRNG function return the same integer every time...?
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
17 Feb 2012 09:38 PM
You don't know what system32 is??

Delete it, it's just 32 gigs of memory that bogs your computer's speed down.
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
17 Feb 2012 09:40 PM
@kingkiller

Oh, that explains it.

@AFF

Not from the wiki...

Can I just see one of you guys make a pseudo code? Like this? Maybe you can make a better/efficient/easier one for me to see.
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
17 Feb 2012 09:42 PM
You don't know what pseudocode is.

Pseudocode is basically code that isn't in an official language, it's just pretty much a mix of English and Program to make clear on the steps to achieve something for any language.
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
17 Feb 2012 09:44 PM
My point is that C++ has a page on chapter 5.9 about random generator. I didn't get the code and I was asking if you can explaiin it to me or right another code and explain me that because I didn't get that lesson.
Report Abuse
myrkos is not online. myrkos
Joined: 06 Sep 2010
Total Posts: 8072
17 Feb 2012 09:46 PM
First, C++ doesn't have an official webpage or wiki because it's a standard that's not owned by anyone. Secondly, your code just tries to generate a pseudo random number using that seed, it does all that math stuff to make it look random.
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
17 Feb 2012 09:48 PM
Well can you show me a simple example of what I want to accomplish?
Report Abuse
myrkos is not online. myrkos
Joined: 06 Sep 2010
Total Posts: 8072
17 Feb 2012 09:50 PM
Why don't you use the rand() function from math.h? It does what you want to accomplish, I think...
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
17 Feb 2012 09:52 PM
I didn't learn that yet...Explain more please.
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
17 Feb 2012 09:53 PM
math.h is a library... hence the h...
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
17 Feb 2012 09:55 PM
The only libraries I know are iostream and stdlib//I think that's if for using exit..


I'm gonna look it up but can you show me the code please! Using that library...
Report Abuse
stravant is not online. stravant
Forum Moderator
Joined: 22 Oct 2007
Total Posts: 2893
17 Feb 2012 10:02 PM
"stdafx.h is an essential library, it's basically like the System32 of C++."

Totally false. stdafx only does something in MSVC, and even when using MSVC you can easily disable use of the stdafx.h file.

stdafx in MSVC is the precompiled header hint for the compiler, so that it has to do less work when compiling large header files what the project includes a lot. The intent is that you put headers which won't change much into it, such as windows.h and the headers for libraries which your project includes.
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
17 Feb 2012 10:06 PM
Wow...That explains a lot!
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
17 Feb 2012 10:08 PM
When I didn't import stdafx.h, my script crashed...
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
17 Feb 2012 10:11 PM
Here, this may help:


Math = {
    startSeed = (os and os.time() or tick())%105;
    seed = (os and os.time() or tick())%105;
    random = function(lower, upper)
        local seed = Math.seed;
        local a = 32156;
        local m = 2^16;
        local c = 1;
        local ttl = 0;
        for i = Math.startSeed, seed do
            ttl = ttl + i;
        end
        ttl = ttl * a + c;
        Math.seed = seed + (ttl % ((m%a)*c));
        if type(lower) ~= "number" then
            if type(upper) ~= "number" then
                return (ttl % m) / m;
            end
        else
            if type(upper) == "number" then
                return math.floor( ((ttl % m) / m) * (upper-lower) ) + math.floor(lower);
            end
            return math.floor( ((ttl % m) / m) * lower );
        end
    end,
    randomseed = function(number)
        if type(number) == "number" then
            Math.startSeed = number;
            Math.seed = number;
        elseif number == nil then
            Math.startSeed = (os and os.time() or tick())%105;
            Math.seed = (os and os.time() or tick())%105;
        end
    end
}

for i = 1, 20 do
    num = Math.random();
    print( "No args:", num );
end

for i = 1, 20 do
    num = Math.random(100);
    print( "Arg 100:", num );
end

for i = 1, 20 do
    num = Math.random(50, 100);
    print( "Args 50, 100:", num )
end

Math.randomseed(10)
print( "Seed changed to 10" )


for i = 1, 20 do
    num = Math.random();
    print( "No args:", num );
end

for i = 1, 20 do
    num = Math.random(100);
    print( "Arg 100:", num );
end

for i = 1, 20 do
    num = Math.random(50, 100);
    print( "Args 50, 100:", num )
end



Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
17 Feb 2012 10:13 PM
Just know that isn't an official random number generator. I just messed around with the maths and changed some values, and I find it working well.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image