Unique Random Integers part II

Last year I wrote about my clumsy implementation of unique random integers system, I’ve used in my Memorable Ladies games. In those the speed isn’t a critical factor. It’s sufficient that the idea works. 🙂

In this post the idea behind unique random integers is the same, but implemented in a faster way.

In the implementation I have used an array that consists of all desired integers and each is drawn in a way that the same integer doesn’t get drawn again. Let’s take a look at the code (I have used Monkey2 programming language in the example):

Image courtesy of nonicknamephoto at FreeDigitalPhotos.net

First an array is initialized with desired integers. Then an random integer from the array is fetched using random index inside the array.  After that the numbers after the drawn number are moved to “left”. For the end the amount of integers is decreased by 1 and the array is resized by the new amount of integers. That’s it.

This way one gets always different random integer from the set of desired integers.

Furthermore, if one would like to get, for example, number four (4) to be drawn three times, one could just include 4 three times in the array.

Depending on what one is doing, one could keep a copy of the original array for future usage.

Although I have used Monkey2 as example programming language, it should be easy to implement similar implementation to many other programming languages quite straight forwardly.

 

 

Scaling ttf-font in Monkey2

In Monkey2 programming language it is possible to load ttf (and otf & fon) font directly and use the DrawText method of canvas to draw the text. But how to scale the font? In this example I made today it is done in a clumsy way, but may give you some ideas…

The source code:

Below is the video related to this post:

Feel free to use my code!

Scrolling of Picture Larger Than Visible Area in Monkey2

I finally today made my first Monkey2 app. I think it was someday in September I finally noticed that Monkey X has evolved into hugely more advanced programming language: Monkey2.

As I wrote in previous post I have an unfinished game project in Monkey X Pro. I think think I’ll finish it someday in Monkey2… I have one other little project in my mind to be done in Monkey2.

This is why I decided to try to make my first Monkey2 program today. In my older post I wrote a  short tutorial on scrolling a picture larger than visible area in Monkey X Pro keeping Android target in mind. In this post the same thing is written in Monkey2 to desktop.

The picture is scrolled with mouse, to change the code to touch screen, just change the mouse related code to touch related code.

Source code below:

Video below demos the source (the text in the video is in video only, though):

Below is a video from the mentioned older blog post written in Monkey X Pro to Android:

Feel free to use my code as you wish.