News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

The Randomize function - what's the point?

Started by Tasselhoff, December 02, 2016, 06:51:56 AM

Previous topic - Next topic

Tasselhoff

Hi, new to the forum, basically new to programming. I freakin love PlayBasic, I might finally learn a programming language!
But while studying the commands I ran into Randomize and just don't get it. You "seed" the random generator so it comes up
with the number you want? Why use a random function at all then? I know I'm probably the only person on earth who doesn't
get why you wouldn't just, I don't know, use the number in the first place? What is a practical application for this?
Any response greatly appreciated. Thanks

Tas

kevin

#1
 Howdy Tas.

    The Randomize command makes the random function produce the same internal sequence.    So each time you call Rnd(), it's computing the next value from the sequence based upon your seed.    This makes Rnd() deterministic, so you get the same results between different runs of the program and more importantly across the many different computers.  

     A programmer might use this behavior to build game scenes such as randomized levels for example.   So the programmer writes a creation algorithm that would set a particular random user defined seed, so the routine produces the same results each time. This saves having to store lots of data in the program.  Which is also know procedural generation.


    Links:

    * Procedural generation
    * Sunny 2d Fractal Mountain

     


    UPDATED:   Added links

Tasselhoff

Oh hey dude I wasn't notified that anyone had answered. Thought I was set to stay logged in but guess not. Okay, uh...yeah. After reading your answer....yeah that doesn't make any sense to me. I must've given the impression that I have mastered computer science and just wanted to make sure you knew what you were doing. That explanation looks a lot like the one in the manual. I can extract no useful information from that. And you're using terms you'd use with other expert programmers.
Can you see how saying, "the programmer writes a creation algorithm that would set a particular random user defined seed, so the routine produces the same results each time" does not elaborate or expound upon anything? I said I didn't get the point of using a random function at all if you're just going to tell it what to return, and by way of explanation you tell me a programmer would use it to tell it what to return. See that's the problem I'm having. Or was having, I gave up on Randomize, was just curious - I can live without it for now.
And here's really the main point. I just simply want to tile the screen with a tileset. In the manual, the example source for LoadMapGFX tells you how to load the image from a file, but not how to divide it into tiles and put them on the screen. Infuriatingly, however, the MakeMapGFX has example source goes into great detail about cutting up your image using tile width & height, even though this command creates your tiles from boxy graphics you've drawn inside the program. Why would anyone do that, instead of load them from a detailed image you made in a paint program? I've been all over the manual, the examples, the forum. Not finding answers.
Another thing is there's no explanation as to the difference between the graphics, Image, and Sprite commands. When to use each, and which of the 50-or-so variations of each you should use. When I click "Images" in the manual, I get a list of 50 commands. There's nothing to help you decide if you should be using GetImage, DrawImage, LoadImage, MakeImage, CreateImage, RenderToImage...I mean these all mean exactly the same thing in my mind. And their definitions all seem the same. Some of them even actually, literally have identical definitions! And it's the same way for the Sprite and Graphics sections.
I'm not at the point where I can look at other's source code and know what's going on in it. But even if I were, I've seen no examples of a simple RPG-style tiling.
I really do appreciate you taking the time to answer. Sorry, I am not only a complete novice, I'm also not very smart & have no programming background so if I get anywhere with this it'll be a testament to PB's accessibility. And I feel like it should be accessible to someone like me, it's BASIC.
Thanks for your time.

kevin

#3
  
QuoteAnd you're using terms you'd use with other expert programmers.

     Yep... unfortunately that's one of the big problems when teaching abstract concepts like computer programming.    It's very difficult to describe usages or concepts to someone without using jargon at some point.    So the help files / forums / examples etc,  all assume some level computing competency and same goes  mathematically understanding from the student.  

   
   
QuoteAnother thing is there's no explanation as to the difference between the graphics, Image, and Sprite commands.

    There's s long tutorial on sprites in the About page under Tutorial label of the current help files.  Although it sounds like your using some old version of PB, so who knows what's in it..  


     
   
QuoteI'm not at the point where I can look at other's source code and know what's going on in it. But even if I were, I've seen no examples of a simple RPG-style tiling.

    To get started that's exactly what you need to do though.  So look at every small example you can find.    Run them, change them, break them if need be.  Then when you do, reference back to the help files about what each statement in the code is doing.  


  * PlayBasic IDE - Getting Started Tutorial: