This is just a quick note, of using the C++11 random functions, to generate a positive list of random integers.
#include <iostream>
#include <string>
#include <random>
#include <cmath>
int main()
{
// Seed with a real random value, if available
std::random_device r;
// Choose a random mean between 1 and 6
std::default_random_engine e1(r());
std::uniform_int_distribution<int> uniform_dist(1, 6);
int mean = uniform_dist(e1);
std::cout << "Randomly-chosen mean: " << mean << '\n';
// Generate a normal distribution around that mean
std::seed_seq seed2{r(), r(), r(), r(), r(), r(), r(), r()};
std::mt19937 e2(seed2);
std::normal_distribution<> normal_dist(20, 1000);
// Loop edited by Xelous
for (int n = 0; n < 10000; ++n)
{
unsigned int l_x = std::abs(normal_dist(e2));
std::cout << l_x << std::endl;
}
}
If you alter the uniform_dist spread to a higher yield, e.g. 1, 1000. Then you increase the randomness of the mean used to generate the sequential seed.
This is taken straight from: http://en.cppreference.com/w/cpp/numeric/random
But, has been run on Coliru.
A blog about my rantings, including Games, Game Development, Gaming, Consoles, PC Gaming, Role Playing Games, People, Gaming tips & cheats, Game Programming and a plethora of other stuff.
Wednesday, 20 April 2016
Friday, 15 April 2016
Windoze Security Loop Hole
This is an example of why I hate Windows...
In a curious case of a security loop hole, in the office, we have a supposedly locked down security situation, none of us are local administrators on our machines, and neither do we have access to any of the very useful parts of our machines.
This is a real pain, and one whereby we often have to call up on the IT Administrators to come and physically, or remotely in a remote desktop session, enter their password for us.
I personally disagree that educated users such as myself have to put up with this situation, I agree totally with data privacy and integrity, however, I wholly disagree with locking people out of things on their machines, such as defragging, or emptying the temporary folders... Or in the case of a programmer, not being able to empty Prefetch or write an ISO to an SD Card.
Anyway, today, I had to write an ISO to an sdcard, the result... I called IT and asked them to run the program for me....
So, just to be clear, I'm logged in as myself:
I am unable to access parts of the system, like the Administrators desktop folders...
I get IT to log the ISO image writer as their elevated user, and the loop-hole begins, you see the program has a standard windows open dialog. And this will work with any standard windows open or save-as dialog, in any program... The program is running as Administrator at this point.
When I select to browse to the file to open, the default folder is the administrators folder by name...
However, because these dialogs all use explorer under the hood, and it's all integrated, they do far more than select a file for you, they let you create folders, browse things and even launch programs...
Yes you can launch a program from a save-sa, or open-sa, browsing dialog!
Lets try to run a command prompt...
Oh, look, it's running as Administrator...
And now I can see the Administrator account directories, which were hidden from be in my own logged on Explorer window..
And I can clear the prefetch folder in windows...
This is clearly wrong, but it's all caused by windows, so what's going on?...
Well, instead of asking the current session (logged in as regular old me) to start the new application instance of Command Prompt, it's asking the application owning the browsing dialog, so command prompt is started under and inherits the user credential level of that program, not my whole session.
What should have happened, well, I believe windows, starting a new program from an elevated user like this should have re-prompted for the user's password again. And indeed, trying to start certain files from the launched command prompt it does go back to the session level to ask for the credentials to start the application with. But not asking and just starting the new application is a problem.
Solutions I can think of include, setting the administrator level account to timeout its password every minute, so one reduces the amount of time a regular user has an unaccredited ability to launch programs. And within a minute the administrator could have started anything the user wanted and left.
A better solution however, might have been to have a user elevation level which could give access only to what the regular user wanted, permissions to use peripherals perhaps, rather than start applications. And the Administrator should not have just started the application as themselves, but should have started the application under themselves as the Hardware only user.
There are other solutions, and I'm sure many I'm not even going to think about, because I don't use Windows systems. If I want security, I simply use Linux and set things up correctly.
Labels:
administrator,
Bugs,
failure,
issues,
problems,
protection,
security,
Windows,
workaround
Thursday, 14 April 2016
Project - Socket 771 to Socket 775 - Xeon Conversion
I've been conducting an experimental project, one I've seen all over the net by others, but which had lots of different information... This is the conversion of a socket 775 motherboard to a socket 771.
First of all, why?... Why would we do this?... Well, the socket 775 is a commercial socket, supposedly sold to us mere mortal customers who buy one machine and one CPU at a time, and the motherboards and processors in the class were/are quite expensive.
We're talking about the Core 2 era, Celeron D, Core 2 Duo, Core 2 Quad. I remember the Core 2 Quad machine I put together was really rather expensive at the time. So, between six and eight years on, we're retiring those machines; yet they cost us a lot of money, and despite depreciation rates we users can still make use of these machines. They can be useful as render farm nodes for 3D or movie work, they can be used as servers, to host basic information, or upload/download points, even as firewalls. All roles they can fall into easily.
I personally am going to be using the machine I've got as a quiet webserver, retiring a venerably serving Pentium 4 Prescott for this old Dell machine.
So, what is the base machine?
Well, it's a franenstein, the in-laws have had me build them a new machine, so they had an Intel D31PR motherboard holding a Celeron D 450, and one gigabyte of RAM, a totally unhelpfully slow machine. Even they noticed it was extremely slow.
From my spares they had enough parts to basically rebuild their machine, which I did, and it left me with their old motherboard. I wanted to upgrade the processor, expand the RAM and add a RAID array controller card, but my budget is extremely low, we're talking £20.
Well on Amazon, I can get a RAID controller card for £13.. This left me £7... Hmm.. Luckily, the IT Department at work were able to donate to me some old DDR2 RAM, so I had the maximum 4GB the board can handle.
£7... Upgrade the processor?.... A challenge... Ebay... Core 2 Duo's and Quads, going for over £25 a pop, most of the Quads were going for £30+. Way out of the budget.
But there were dual core Xeons for around £4... And I saw this hack out there on the wires, so I set about working.
The first step is to strip everything down, clean it perfectly, and get a scalpel. The first part of the modification is to remove the tabs from the processor, these tell the user which way to orientate the CPU for insertion, they do nothing else... A consumer CPU is orientated horizontally, so there are tabs top and bottom to stop you inserting the wrong CPU.
And the Xeon has gaps left and right, meaning it'll bounce off these tabs on the socket 775.
Taking the scalpel, I started to cut the tabs, now I DID THIS WRONG! A much better approach is to leave the current CPU in there, with the tabs engaged into the socket 775 CPU, and then cut between the CPU and the edge of the socket. So the CPU acts as a guide and the delicate socket pins are protected out of sight below the CPU.
And clean the cuts you make up.
Remove any debris...
Then you need to go back to ebay, and buy a Xeon Socket Modification sticker, this is a little sticker, which will cover two rows of connections on the bottom of the CPU, it will allow most of them to pass through the plastic, but two pins are headed with a little connector, and behind the sticker these connectors actually swap the two pins over.
So, two pins, and the orientation, that's all that's different about a Socket 771 and a Socket 775 CPU.
The stickers are bar shaped, so they indicate which pin to swap, but lay the CPU down with the notches to the top, and from the bottom count 10 connectors from the bottom right, moving left... Voila, stick it down carefully.
Insert into the Motherboard socket now, so the notches are to the "top" of the socket, add the heat-sink assembly, and build it back up on your work bench.
Now, some videos and advice says you need to go to sites, and download patches for your motherboard. During my project here I've found most Intel brand motherboards do not need any patching, only third party boards. It seems Intel include all the microcode for all their processors (this is only a guess, I have no proof other than using five different intel boards, and two none-intel boards and always having to patch the non-intel branded ones, whilst the intel ones just work).
Then powering on...
It worked, I've gone from a Celeron D 430 to a Xeon 5130. They're very similar processors, but the Xeon has dual cores and a much faster FSB.
My YouTube play list, for my crappy videos covering this project can be found here:
Wednesday, 13 April 2016
RIP Dude - First Anniversary
I can't believe it's been a whole year since my beautiful best boy had to leave us...
I miss you everyday my big yellow beauty.
Sunday, 10 April 2016
Arc Welding Arduino Code
From my YouTube Video:
int ledPin = 13; // LED connected to digital pin 13
void setup()
{
pinMode(ledPin, OUTPUT);
}
void loop()
{
int i,count;
count=random(10,60);
for (i=0;i<count;i++)
{
digitalWrite(ledPin, HIGH); // set the LED on
delay(random(60));
digitalWrite(ledPin, LOW); // set the LED off
delay(random(200));
}
delay(random(800,2000)); // wait a random bit of time
}
int ledPin = 13; // LED connected to digital pin 13
void setup()
{
pinMode(ledPin, OUTPUT);
}
void loop()
{
int i,count;
count=random(10,60);
for (i=0;i<count;i++)
{
digitalWrite(ledPin, HIGH); // set the LED on
delay(random(60));
digitalWrite(ledPin, LOW); // set the LED off
delay(random(200));
}
delay(random(800,2000)); // wait a random bit of time
}
Monday, 4 April 2016
Junk PC - Celeron to Core 2 Quad
You may guess I've taken what was basically a junk PC from the in-laws and turned it into a fairly decent machine, what could it do?... Well it was reported to be showing "video like an old slide-show", "internet pages took so long to load we could boil the kettle" and a myriad other little things.
To hear those kind of reports from regular users of 70+ years of age, rang alarm bells, something needed to be fixed.
The machine was:
Intel Celeron 450 @ 2.2ghz
1GB DDR2 400Mhz RAM
Intel HD 3000 Graphics (on board)
320GB western digital carvier blue HDD
I've raided ebay, Amazon and my own spares, and the machine is now, re-cased, with new air-flow/cooling, and it's significantly improved:
Intel Core 2 Quad Q6600 @ 2.4ghz
4GB DDR2 800Mhz RAM
Asus GeForce 610 GT (1GB DDR3)
120GB Scandisk Performance SSD
With a nice new box, the thermal paste, a cleaning air-can and all the bits I needed the upgrade cost just shy of £60.
And the new incarnation of the machine runs:
World of Warships - High Settings - 50FPS
World of Tanks - High Settings - 50-60FPS
Minecraft - Fullscreen - 100+FPS
Arma 3 - Medium Settings - 25FPS
Arma 2 - High Settings - 60FPS
H1Z1 - Medium Settings - 50FPS
This is impressive performance from a bog standard Intel G33 Motherboard and a bunch of spare parts.
Certainly £60 was a very fair price for all this kit, and I can't help but thank the moron on ebay who sent me a mail abusing me for listing "such old shit at a high price"... because through whatever machinations I kept the kit, and here we are just a month on with is back in use and blowing through performance like no-ones business.
Saturday, 2 April 2016
PC upgrades, and more coding ideas
As you can see, I'm in the middle of working on some PC kit. Upgrading the in-laws old kit and retiring one of mine in the process.
I'm going to be working on the second part of my functional programming post later today, covering some alternate languages and better explaining maintainable code with relation to those parameters being passed.
I'm going to be working on the second part of my functional programming post later today, covering some alternate languages and better explaining maintainable code with relation to those parameters being passed.
Subscribe to:
Posts (Atom)














