Procedurally generating a solar system

27 April, 2017

Procedural generation has always been of interest to me, and solar systems are cool. So I decided to explore procedural generation by procedurally generating a solar system! Below is a solar system that has been generated based on a pseudo random seed. Below is an example of a generates Solar System. Refresh the page for a new randomly generated Solar System! click Here for a full screen version that is not scaled down and looks nicer!


To procedurally generate anything we first need a seed to base our generation on. We will seed the random number generation to our seed. Once we have a seed the rest of the generation will be based on this. This means that the same seed will always generate the exact same solar system, so if there is a solar system that is particularly nice the seed can be saved to re-generate the exact same solar system at any given time. I have written this in HTML5 using the phaser framework and thus my code to generate and set a random seed is as follows:

Math.seed = Math.floor(Math.random() * (89898989898989898989 - 29898989898989898989 + 1)) + 29898989898989898989;

Where Math.seed is the value that we will use as our unique seed.

Math.randomSeed = function(max, min) {
    max = max || 1;
    min = min || 0;
    Math.seed = (Math.seed * 9301 + 49297) % 233280;
    var rnd = Math.seed / 233280;
    return min + rnd * (max - min);

Math.randomSeed is the random function that we will use to generate pseudo random numbers based on the seed generated and stored in Math.seed. Of particular note is:

Math.seed = (Math.seed * 9301 + 49297) % 233280;

This is a general math equation to generate pseudo random numbers, more info on this is available at:

Once the seed is generate we can begin to generate our solar system. Our solar system consists of 4 elements: The sun, Planets, Moons and Stars. Each of these are generated based on the seed. Some things like the planets are affected by the sun that is generated. Due to this we must generate the solar system in the following order:
Stars – only affected by the seed
Sun – only affected by the seed
Planets – Affected by the heat of the sun and distance from sun. More on this later
Moons – Affected by the distance from the planet and the climate of the planet
We will look at how each element is generated.


Generating the stars

The stars are probably the easiest to generate as the stars are based on per-defined images. There are 9 possible images that will be used for the stars, they are all similar with a slightly different layout:


The image to be used is chosen at random based on the seed:

  this.type = parseInt(Math.randomSeed(1,10));
  this.sprite = game.add.sprite(960, 960, 'stars'+ this.type);

Once one of the 9 images is chosen we set a random rotation for it in 90 degree intervals.

  var rotation = parseInt(Math.randomSeed(1,5));
  this.sprite.angle = rotation*90;

In doing this we get a total of 36 different possibilities for the layout of the stars as each of the 9 images have 4 different possible rotations.


Generating the Sun

The Sun is the core of the solar system and will have an effect of every planet and moon that is generated. To generate the Sun the first thing we need to do is define all the properties that a sun has. For this project I decided a sun was determined by its Type, Size, Heat and Sprite. In this case Type is an arbitrary value to add some extra variation. Size is pseudo random and Heat is based on both the Type and Size of the sun. These 3 values are set using our random function defined earlier.

	this.type = parseInt(Math.randomSeed(1,6));
	this.size = parseInt(Math.randomSeed(1,9));
	this.heat = (this.size*this.type*5)+30;

The last thing we need to do is set a sprite for the sun. The sun much like the stars have a pre-defined set of images that can be used:


However the sprite that is chosen to represent the sun is based on the sun type and as a result also corresponds to the heat of the sun:

this.sprite = game.add.sprite(10, 10, 'sun'+this.type);


Generating the planets

Much like the sun to generate planets we must first determine all the properties that make up a planet. I decided each planet should have a Size, Distance, Water Level, Speed, Temperature, Climate, Name and Sprite. Each value is determined based on the Seed and also often the Sun that has been generated.

The Size, Distance and Water Level are based only on the Seed:

	this.size = parseInt(Math.randomSeed(1,4));
	this.distance = parseInt(Math.randomSeed(3,9));
	this.waterLevel = parseInt(Math.randomSeed(1,10));

The Speed is based on both the Seed and Distance:

	this.speed = (parseInt(Math.randomSeed(10,25)))-this.distance;

The planets temperature is base on the Seed, Heat of the Sun and Distance from the sun:

	this.temp = this.sunHeat – (this.distance*8);

The climate is based on both the Water Level and Temperature of the planet. I wrote a separate function to work out the climate of the planets based on these values.

planetClass.prototype.getClimate = function(water, temp){
	var climate;
	if(water < 4){
		if(temp < 1){climate = "plains"}
		else if(temp < 41){climate = "desert"}
		else{climate = "fire"}
	}else if(water < 7){
		if(temp < 1){climate = "earth"}
		else if(temp < 41){climate = "earth"}
		else{climate = "tropic"}
		if(temp < 1){climate = "ice"}
		else if(temp < 41){climate = "tropic"}
		else{climate = "gas"}
	return climate;

Each planet should have a name to make is more unique. Each name is based on the Seed and a pre-defined list of names that are available. Depending on the Seed a random name is chosen and a random number added to the name.

planetNames = ["Zeus","Hera","Poseidon","Demeter","Ares","Athena","Apollo","Artemis","Hephaestus","Aphrodite",
"Hermes","Dionysus","Hades","Hypnos","Nike","Janus","Nemesis","Iris","Hecate","Tyche"] = parseInt(Math.randomSeed(0,20)); = planetNames[] + parseInt(Math.randomSeed(0,200));

The last thing to do is set an appropriate sprite for the planets. Again this is chosen from a pre-defined selection of planet sprites.


The sprite that is chosen for the planet is a direct result of the climate of the planet:

this.sprite = game.add.sprite(10, 10, this.climate);


Generating the Moons

Again the generate the moons we need to define the properties that a moon has. I decided each moon needed a Size, Speed of Orbit, Type, Distance and Water Level.

The Size, Speed of Orbit and Type are directly related to the Seed:

	this.moonSize = parseInt(Math.randomSeed(1, 4));
	this.speed = parseInt(Math.randomSeed(5, 10));
	this.type = parseInt(Math.randomSeed(1,4));

The distance is based on the distance of the moon from the sun.
The Water Level is based on the Water Level of the planet

The Sprite for the moons is chosen from the same selection of sprites as the planets they are however scaled down. The sprite chosen for the moons directly corresponds to the Type of moon:

		case 1: this.sprite = game.add.sprite(10, 10, 'desert'); break;
		case 2: this.sprite = game.add.sprite(10, 10, 'fire'); break;
		case 3: this.sprite = game.add.sprite(10, 10, 'plains'); break;


Adding an AI to battle for control of the Solar System Generated

 For a little bit of extra fun I created a basic AI that will battle for control over the generated Solar system. This becomes Red vs Green where each AI is assigned a starting planet. Each planet is given a “ship production rate” to generate ships. The AI will send ships from planets it owns to try capture planets it does not own in an attempt to control the entire Solar System.


The full source for this project is available on my Github at:



SCCM PowerShell Task Sequence GUI

07 March, 2017

Playing around with our Task Sequences in SCCM I came to the realization that we have numerous post install tasks for optional software when an Imaged PC is for a particular department or entity. This is due to different departments having different software requirements. I started toying around with the idea of a software selection GUI as part of the Task Sequence that will allow customization of post install software in the aim to make all deployments ‘one touch’.

After some research and work I came up with a basic GUI with a few customization's:


However, this is still limited and does not cover all of our use cases, so we are still left with some post install tasks. After some more work I came up with the following ‘final’ GUI:


From this GUI we are able to choose all the combinations of required software for all departments and entities. No more post install tasks for any PC’s.

I had to do a few things to get this working as desired. But at the core of it, each of the tick boxes sets an MDT Task Sequence Variable. The variable weather ticked or not determines if the software installation step should proceed.

MDT Task Sequence Variables
The task sequence itself has some additional steps to create the variables. Each variable requires a separate step for the variable creation. I found the variables needed to be created in the task sequence before the PowerShell script that sets the variables values can be run.


All of the variable are set to False when created in the task sequence. The PowerShell script will later set the ones that are ticked to True.



Conditional Application Installations
We have the requirement that some applications are installed on every PC that we image, these applications are installed regardless of the options chosen. For the conditional application installations, I have created a separate step for each one.


Each of these steps simply installs a single application.


Under options I have set the condition that the Task Sequence Step only run if the corresponding variable is set to True.



The PowerShell Script
Creating GUI’s in PowerShell is tedious and annoying but there is plenty of information on how to do that so I will be glossing over the GUI creation part. The important part of the script is retrieving the value from the check box and injecting it into the Task Sequence variable. A minimal example how this works would be:

    #Get Variable from Form
    $installPDF = $pdfCheck.Checked #where $pdfCheck is the checkbox

    #set variable in the task sequence
    $TSEnv = New-Object -COMObject Microsoft.SMS.TSEnvironment 
    $TSEnv.Value("installPDFAnnotator") = "$($installPDF)"

The script needs to be made into an SCCM Package so that we can run the script from the Task Sequence. The source contents for the package should include the script to be run, ServiceUI.exe and any assets required by the script. In my case the company logo.


The package is nothing special, you only need to set the source files for it. And distribute it the required Distribution Points.


Incorporating the script into the task sequence requires adding a step ‘General > Run Command Line’. The command line step should look similar to the following:


The two main things to note here is the command line is pointing to the PowerShell script that is part of the package and that the package is selected. You just need to make sure that you declare all the MDT Task Sequence variables before running the PowerShell step “Prompt For Image Configuration”


And that should be it!

Office 365 Shared Mailbox Sent Items Folder

20 February, 2017

When creating a shared mailbox in Office 365 the default behaviour for items sent from this mailbox is odd. When a user who has access to the shared mailbox sends an item from or on behalf of the mailbox the item goes into the users ‘sent items’ folder. The sent item will not appear in the ‘sent items’ folder of the shared mailbox.

There is no obvious way to configure items sent from a shared mailbox to appear in the ‘sent items’ folder of the shared mailbox. This however can be configured quite easily from PowerShell. To do this you will first need to establish an Office 365 session in PowerShell. To establish a session:

Get Credentials

$cred = get-credential

Create a session with using the saved credentials

$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $cred -Authentication Basic -AllowRedirection 

Import the session

Import-PSSession $session -AllowClobber 

Once you have established the connection to Office 365 you can configure the ‘sent items’ behaviour or shared mailboxes.
To configure emails that are Sent As:

set-mailbox <mailbox name> -MessageCopyForSentAsEnabled $True

To configure emails that are sent of behalf of:

set-mailbox <mailbox name> -MessageCopyForSendOnBehalfEnabled $True

If you later want to stop the shared mailbox’s from saving sent items into their own ‘sent items’ folder, you can simple set the values in the commands above to $false instead of $true.

Adding Azure Remote App Users with PowerShell

16 February, 2017

Adding azure remote app users with PowerShell is a relatively simple task and many times quicker than waiting for the clunky web based UI. The first thing to do is install the ‘Microsoft Azure PowerShell module’.

Once you have this module installed you need to add an Azure account. You only ever need to do this once. It’s as simple as running the following cmdlet and signing in.


Once you have signed in you will need to select the subscription that you want to add the user to. You can get a list of all you subscriptions using:


select a subscription use the following:

Select-AzureSubscription <Subscription Name>

Once you have selected your subscription you can begin to add users. This is as simple as running:

add-AzureRemoteAppUser -CollectionName <Collection Name> -Type orgid -Userupn <User UPN/Email>

This will then add the user to the selected collection under the selected subscription and allow them to start using remote apps.

SCCM 2012 R2 and PowerShell

14 February, 2017

To use PowerShell with SCCM you will all you need to do is import the module. If you don’t have the module installed you can get it from here: Note that you will also need to have Configuration Manager Console installed on your computer.

Once you have the module installed, import the module using the following command:

import-module "C:\Program Files (x86)\Microsoft Configuration \Manager\AdminConsole\bin\ConfigurationManager.psd1" 

Once you have imported the module you will need to connect to your site using the following:


Where ‘x’ is your site code. In my case this is:

CD PR1: 

Once connected to your site you can query information about your site using:


There are a whole bunch of cmdlets for SCCM that will allow you to do many tasks directly from the PowerShell console. I have a few SCCM scripts on my GitHub at:

As I create more scripts utilising SCCM I will be adding them to my Git. So far I have used PowerShell to query User and Device memberships from collections and export the results out to CSV’s for reporting.

Log Off an Azure Remote App User via PowerShell

15 November, 2016

I wrote this script because Azure Remote App is shit and always causes problems for users. One of the bigger problems is when a user’s application within Azure Remote App freezes, the user can’t simple restart the remote app as the server keeps the session and frozen/crashed application alive.

The solution to this is to log the user off the server. This module is designed to be a super simple way to log off a user just by using their email address that is associated with the Azure Remote App account.

function global:end-azureSession{
        [parameter(HelpMessage='your username/email for azure')]
        [parameter(HelpMessage='your password for azure')]

    #define our set variables for the penrith enviroment
    $azureSubscription = 'PCC-AAE'

    #create credentials
    #$secPass = ConvertTo-SecureString $password -AsPlainText -Force
        #$AzureCred = New-Object System.Management.Automation.PSCredential ($username, $secPass)
        $cred = Get-Credential
        #$AzureCred = New-Object System.Management.Automation.PSCredential
    #this will throw exception even if success.... so yep... this is my work-around...
    try{Add-AzureAccount -Credential $cred}catch{write-host "Connected to Azure" -ForegroundColor green}

    #Select subscription
    Select-AzureSubscription $azureSubscription

    #disconnect user
    write-host "Disconnecting user, this may take a while....." -ForegroundColor green
        invoke-AzureRemoteAppSessionLogoff -CollectionName rappaaeprod -UserUpn $userEmail -confirm:$false >$null 2>&1
        write-host "diconnected..." -ForegroundColor green
        $errorMessage = $_.Exception.Message
        if($errorMessage -eq "InternalError: The server encountered an internal error. Please retry the request."){
            write-host "User has been disconnected" -ForegroundColor green
            write-host "ERROR: User connection to Azure not found" -ForegroundColor red


Example 1: this will prompt you for credentials then end the users session


Example 2: You can save and pass credentials to the module

$cred = get-credential
end-azureSession $cred



Home ← Older posts