Monthly Archives: September 2015

A Mersenne_Twister Implementation in PHP

I am confused. I found this great Mersenne_Twister implementation to compensate for the fact the at mt_srand() and mt_rand() don’t generate predictable sequences since PHP 5.2.1. From

The Mersenne Twister implementation in PHP now uses a new seeding algorithm by Richard Wagner. Identical seeds no longer produce the same sequence of values they did in previous versions. This behavior is not expected to change again, but it is considered unsafe to rely upon it nonetheless.

What confuses me is that I cannot figure out where I found this code. In my notes have it at in the comments – but I cannot re-find that comment on mt_srand() entry – perhaps it was deleted.

So that it is not lost, I reproduce it here.

class Mersenne_Twister
  private $state = array ();
  private $index = 0;

  public function __construct($seed = null) {
    if ($seed === null)
      $seed = mt_rand();


  public function setSeed($seed) {
    $this->state[0] = $seed & 0xffffffff;

    for ($i = 1; $i < 624; $i++) {
      $this->state[$i] = (((0x6c078965 * ($this->state[$i - 1] ^ ($this->state[$i - 1] >> 30))) + $i)) & 0xffffffff;

    $this->index = 0;

  private function generateTwister() {
    for ($i = 0; $i < 624; $i++) {
      $y = (($this->state[$i] & 0x1) + ($this->state[$i] & 0x7fffffff)) & 0xffffffff;
      $this->state[$i] = ($this->state[($i + 397) % 624] ^ ($y >> 1)) & 0xffffffff;

      if (($y % 2) == 1) {
        $this->state[$i] = ($this->state[$i] ^ 0x9908b0df) & 0xffffffff;

  public function getNext($min = null, $max = null) {
    if (($min === null && $max !== null) || ($min !== null && $max === null))
      throw new Exception('Invalid arguments');

    if ($this->index === 0) {

    $y = $this->state[$this->index];
    $y = ($y ^ ($y >> 11)) & 0xffffffff;
    $y = ($y ^ (($y << 7) & 0x9d2c5680)) & 0xffffffff;
    $y = ($y ^ (($y << 15) & 0xefc60000)) & 0xffffffff;
    $y = ($y ^ ($y >> 18)) & 0xffffffff;

    $this->index = ($this->index + 1) % 624;

    if ($min === null && $max === null)
      return $y;

    $range = abs($max - $min);

    return min($min, $max) + ($y % ($range + 1));

I also wrote a PHP Mersenne_Shuffle() function called that produces a predictable shuffle using the Mersenne_Twister().

function Mersenne_Shuffle($arr, $seed=-1)
    if ( $seed == -1 ) return $arr;
    $mt = new Mersenne_Twister($seed);
    $new = $arr;
    for ($i = count($new) - 1; $i > 0; $i--)
        $j = $mt->getNext(0,$i);
        $tmp = $new[$i];
        $new[$i] = $new[$j];
        $new[$j] = $tmp;
    return $new;

Why PHP chose to break this in the name of progress I don’t understand. Ah well. Here is the workaround. If I need to acknowledge someone – let me know.

Using git subtrees in Tsugi

I am starting to build PHP and Java implementations of my Tsugi libraries and I want to share the static content (JavaScript, CSS, etc) between them all so they all are effectively testing the same core code as much as possible and I don’t want to change things two places. Here are my repos:

I toyed with submodules – but adding “–recursive” to all “git clones” seemes icky and it seemed ike “git pull” in the world of submodules was clunky – I did not even bother to figure it out before I gave up on submodules.

Goodbye git submodules hello git subtrees.

I read these blog posts to learn up:

Conviently in the modern version of git – it knows how to blast submodules so undoing my use of sub modules was a simple matter of:

git rm static
git push

Of course my repo was broken at this point so I quickly needed to add the static folder back as a subtree in with these commands. Note that I did not do the “remote-add” and just put hte full URL if the repo in place of the remote on the subtree commands. I will add the remote if I start pushing from tsugi to tsugi-static.

$ git subtree add --prefix=static/ master
git fetch tsugi-static master
warning: no common commits
remote: Counting objects: 159, done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 159 (delta 3), reused 0 (delta 0), pack-reused 150
Receiving objects: 100% (159/159), 1.14 MiB | 0 bytes/s, done.
Resolving deltas: 100% (31/31), done.
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> tsugi-static/master
Added dir 'static'

$ git push
Counting objects: 160, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (125/125), done.
Writing objects: 100% (160/160), 1.20 MiB | 0 bytes/s, done.
Total 160 (delta 32), reused 149 (delta 30)
   55ec2c7..87c5f1d  master -> master
0587388153:tsugi csev$ git status
On branch master
Your branch is up-to-date with 'origin/master'.

Just to be sure I putched my clone and re-cloned tsugi and poof! My static content was there in a folder just like I like it – no –recursive required.

On to the git pull when the subtree repo is updated..

In general I will make changes in a separately checked out version of tsugi-static, push them up there and then do a pull into tsugi using these commands. It is a merge – but as long as you keep your local copy of the subtree clean – it is a trivial merge. Of course then you need to push to origin master since subtrees have a full copy of the subtree in the repo:

$ git subtree pull --prefix=static master
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (1/1), done.
remote: Total 3 (delta 2), reused 3 (delta 2), pack-reused 0
Unpacking objects: 100% (3/3), done.
 * branch            master     -> FETCH_HEAD
Merge made by the 'recursive' strategy.
 static/ | 8 --------
 1 file changed, 8 deletions(-)

$ git push origin master
Counting objects: 5, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 858 bytes | 0 bytes/s, done.
Total 5 (delta 2), reused 0 (delta 0)
   87c5f1d..6397cb5  master -> master

And that is all there is to it.

This tricky subtree pull is only for the repo that pulled in the subtree initially. Any forks of that repo are unaware that the “static” folder is a subtree and for them “git pull” updates both the repo and the subtree automatically.

Transition from Programming for Everybody (Python) to Python For Everybody

This blog post is to summarize the steps we are taking to transition students who have previously taken or are currently enrolled in our Coursera Programming for Everybody (Python) (PR4E) course now that we have converted the course to the new Coursera platform and made it part of our Python for Everybody (PY4E) specialization.

  • For students who earned a certificate in Programming for Everybody (Python) prior to September 2015: These students will be given credit for the first two courses in the Python specialization and can simply purchase certificates for courses 3, 4, and the capstone to complete the specialization. If you sign up for the first or second course, you should see a price of $0 for the course (screenshot) and if you sign up for the specialization, you a reduced price for the specialization if you sign up for the whole specialization from the specialization page.
  • For students who completed Programming for Everybody (Python) prior to September 2015 but did not pay for a certificate: These students can start in the third course in the specialization (still completely free) and complete courses 3 and 4 in the specialization.
  • For students who registered for the upcoming October 5 session of Programming for Everybody course and paid for a verified certificate: These students will be given a refund and voucher will be added to your account so they can register for verified certificates in the first two courses in the Python Specialization for the exact same cost as registering for the single course verified certificate in Python for Everybody. If you enroll in either of the first two courses in the specialization, you will see a price of $24 (half of the original $49 you paid for the October 15 session). (screenshot)
    Please be patient with the refund: It will take 2-3 days for your refund to show up in your bank account. If after 2-3 days you still do not think that your refund has arrived, contact Coursera Technical Support.
  • For students who registered for the upcoming (October 5) session of Programming for Everybody course but did not pay for the certificate: These students can start at course 1 in the specialization – which is free to enroll.
  • For students who registered for the upcoming October 5 session Programming for Everybody course and were given financial aid: You will need to apply for financial aid for verified certificates in the first two courses in the Python Specialization. Coursera assures me that those who received financial aid in Programming for Everybody will be given financial aid for the courses in the specialization.

The Courses in the Specialization

Here are the courses in the specialization:

  1. Getting Started with Python Chapters 1-5
  2. (Starts September 15, and every six weeks thereafter)

  3. Python Data Structures – Chapters 6-10
  4. (Starts September 15, and every six weeks thereafter)

  5. Using Python to Access Web Data – Chapters 11-13 (Students who have completed PR4E start here)
  6. (Starts October 27, and every six weeks thereafter)

  7. Using Databases with Python – Chapter 14-15
  8. (Starts December 8, and every six weeks thereafter)

For those who are just getting started, the best strategy is sign up for the first course now and the second course in six weeks. For those who know all the material from Programming for Everybody – they can wait until October 27 to start course #3.

Teaching Four Free Python Courses on Coursera, Reflecting on Specializations

Update: As of January 2017, Coursera has implemented a “pay wall” on the assessments in the Python for Everybody courses. My preference was not to have a paywall but Coursera insisted. As a result, I have made all of the materials and exercises available for free at – this site teaches Python 3 but the exercises can be done in either Python 2 or Python 3.

Update: As of April 2017, we have unlocked the Capstone (course 5) on Coursera – it is no longer necessary to complete all of the first four courses before joining the capstone.

In interacting with my current students from Programming for Everybody (Python) – (a.k.a. #PR4E), there are clearly a lot of questions about how Specializations work on Coursera.

Specializations are multi-course sequences with a Capstone. All of the courses that make up the specialization except the Capstone remain free. Here are my four free Python courses that cover all the material in my Python for Informatics textbook (now available in English, Spanish, Korean, and Chinese). The first two courses are six weeks long and cover the same material as my 11-week Programming for Everybody (Python) course on Coursera.

You can find all of Colleen van Lent’s free Web Design for Everybody courses here on her instructor page. You can also find all my classes at my Coursera instructor page.

The Specializations and Capstones

The specializations are multi-course sequences that require you to earn and pay for certificates in all of the courses that make up the specialization and then enroll in and pay for the Capstone course. As an example, it costs around $400 to pay for the four courses and capstone certificates for my Python for Everybody specialization. Colleen’s Web Design for Everybody specialization is also around $400. Both specializations have “pay up front” discounts.

A key element of the capstone course is that it is not “new material” – all the material that you need to know is available in the free classes. You are supposed to have already learned the skills in the courses that led up to the capstone. The capstone is more project-oriented with more feedback and a smaller group of students who we know already have pre-requisite information and so are well-prepared to take the capstone. By the time you get to the capstone, you might even know some of the other students in your class. Study groups may have formed and have been functioning for months. Capstones may have industry participation or other benefits.

My Thinking on Specializations and Capstones

When I started with Coursera back in 2012, all I ever dreamed of was to teach one course and have fun with it and engage with people around the world. I chose Internet History, Technology, and Security because I could showcase all my interviews of famous innovators and create a very special course. I wanted to get students who were afraid of technology to the point where they liked technology. This course was very successful with close to 200,000 enrollments since 2012.

I also felt very lucky to be allowed to teach a second course called Programming for Everybody (Python) where I was able to build a dream course that would focus on teaching programming to those who had absolutely no prior experience. PR4E was also a great success, with over 3/4 million students taking the course since 2014. It also was very successfull in meeting my goal of getting people *into* technology even if they were scared or had no experience.

But, from the beginning, there has been a constant demand for more courses. Both online and in my face-to-face office hours around the world there was a constant push for “more courses”. Students did not want to just get a taste and lose their fear, they wanted real skills that they could use to make real changes in their careers.

Moving from “one great course” to “job-applicable skills” is not as easy as it seems on the surface. It requires a willingness to stick to something for more than a few weeks. In college, courses build upon one another – not all courses can be “prerequisite free”.

So if we are to build online activities that begin to move students through 20-30 weeks of course material, there needs to be some structure and some buy in – and an ultimate goal that helps put all the work into some perspective. There needs to be some kind of “graduation” – some kind of light at the end of the tunnel.

Because as you progress through the material in a “curriculum”, the material gets more difficult and the likleyhood of dropout goes up dramatically. So educators build structures to help students make it all the way to the end.

The specializations are that needed structure and the capstone is the light at the end of the tunnel – that graduation – that goal that makes all the effort worthwhile.

And if you imagine that you are going to invest 6-9 months of effort in a sequence of increasingly difficult courses – having to pay for them is a motivational plus in a way. When we think about “paying” for these courses, remember that Coursera has a very active financial aid program that makes sure that we are not blocking access to these courses (including the specialization and capstone) for those unable to pay. For those able to pay, you can pay as you go or pay up front. You can take a course and choose to get the certificate after you know you will succeed in the course.


I personally am 100% committed to making all my courses and material free to everyone. If my goal is to truly “teach everyone” I cannot and will not hide my content behind a paywall.

I think that the approach that Coursera is taking balances free access and pay access in a way that makes sure that all have access to the learning they want. And Coursera and University of Michigan need some way to justify the significant expense in putting out all of this free material. For those who can afford to pay, I hope that you do pay. For those that cannot pay, take a look at financial aid options. And for those who just want to pick and choose courses for a more easy-going pace of professional and personal development, you should be thankful for the effort that Coursera and the University of Michigan have put into specializations over the summer. Because of specializations, the number of free courses available has nearly doubled in the past six months.

It took me three years to get to providing two courses on Coursera. Over the summer, my colleague Colleen van Lent built four completely new free courses on web design and a web design specialization. The pace of creating better ways to learn is accellerating and specializations are just one important part of the mix.

We all fear change – I sure know that I do. But if we know one thing about change it is that the more things change the more things stay the same. I am pretty sure that Coursera now provides more high-quality free courses to the world than the rest of the MOOC providers combined. And we are moving up the value chain from courses that lead to wonderful personal growth to specializations that change your career arc.

Announcing University of Michigan / Coursera Python and Web-Design Specializations

I have been involved with Coursera and MOOCs since early 2012 when I created my Internet History, Technology, and Security #IHTS course on Coursera. That was followed up in 2014 by my Programming for Everybody (Python) #PR4E course. Over the past three years we enrolled nearly 200,000 students in #IHTS and nearly 600,000 students in #PR4E.

Both of these classes are designed as “on-ramps” for students to take as their first foray into technology. The good news is that I think that we were very successful in the pacing and content of both classes so that they were accessible to all students regardless of prior knowledge or experience. But at the end students were always left wanting more advanced material.

So this Fall, we are expanding the Python course into a five-course Specialization called Python for Everybody and adding a whole new specialization taught by my University of Michigan School of Information colleague Colleen van Lent called Web Design for Everybody. We chose the “..for Everybody” names because we are both committed to teaching courses that had no pre-requisites except for a willingness to work and learn.

To transition to the “Python for Everybody” specialization, we have broken the material in the 10-week “Programming for Everybody” course into two six week courses that we now call “Getting Started with Python” and “Python Data Structures”. And to that we add two more six week courses titled “Using Python to Access Web Data” and “Using Databases with Python”. These two new courses will cover Chapters 11-15 in the textbook.

Here are the links to the four courses that now cover the entire Python text book:

Those students who paid for and earned a verified certificate in any of the Programming for Everybody sessions (all the way back to April 2014) can jump right to the third course in the specialization. Your Programming for Everybody verified certificate will be treated the same as earning certificates in each of the first two new courses in the Python for Everybody specialization.

For those students who could not complete the course due to time commitments or other issues, you will be able to re-start at the beginning on the new Coursera learning platform that is much more flexible in terms of deadlines. Courses start every 6-8 weeks, and if you don’t complete the course in one session, you can join the next session and your homework and quizzes follow you from session to session so you don’t have to start over. If you want to work quickly, you can see all the material as soon as the course opens so you can race through as fast as you can go. The advantage of the new platform is that there is a wider range of paths to completing the course successfully.

Live Office Hours

If you have any questions about the courses I have taught or the specializations going forward, Colleen and I will be having live online office hours (more like a question and answer session) on Tuesday September 8, at 12:30 PM Eastern time using a Google Hangout. That is a great time to ask questions of either of us. The URL for the live office hours is:

So all in all, it is a super-exciting time for us. Colleen and I have worked all summer to prepare these new courses and we hope you will join us this Fall in one or many of these classes.

Sakai 11 – Skin Contest

(This is taken from a posting to the Sakai mailing lists)

Announcing a Sakai 11 skin contest!

Winner(s) to be announced at the Sakai Virtual Conference – November 4th, 2015.


One of the key features for the next major release of Sakai is responsive design, or better support for small screen sizes like cell phones (aka code name Project Morpheus). Thanks in large part to contributions from NYU, Marist, and Murcia, we have a great UI design to start with. Now we want to take it to the next level! Help us go there!

Come up with your best design, take screenshots, document your rationale for the design, provide details (feel free to use, it may help).

Submission process

Working on it. Will have more details in weeks leading up to the conference. But there’s no reason you can’t start working on it today!

Getting started

To get started, it is recommended that you download a copy of Sakai 11 to run on a test server, or at least take a look at our master copy on our nightly server (create an account or use default account “instructor” with password “sakai”). See what we’ve already got, and build from there.

Take into account internationalization issues (the ability to localize Sakai to a geographic location’s cultural and language preferences) and accessibility, so that people with physical limitations are not limited in their use of Sakai. A quick and easy resource to start with is or

Come up with your color schemes, come up with any interface changes, consider desktop and mobile screen sizes. Mock up your schemes as images that anyone can access (jpeg, png, tiff, etc).


As Sakai continues to evolve and innovate we need to be aware of a number of issues. As mentioned above, internationalization and accessibility are a couple of examples. But we also have maintainability and consistency to consider. A subset of the community actively fixes bugs and maintains tools. We call these folks the Sakai Core team. This team needs to feel comfortable that they can support the code. And we have efforts underway to make Sakai tools have a common look and feel, so that they will be easier to use overall.

So feel to go crazy and wild with your designs. The winner(s) will be based on aesthetic beauty, functionality, and creativity. The Sakai Core team will pick and choose which elements will work best, possibly across several designs, if that makes sense. Also, the Sakai Core team and the Sakai PMC will consider the timeline of Sakai 11 and figure out which skin features will make it into the Sakai 11 timeline and which will need to wait until the next maintenance or major release. For these reasons, 2 or 3 members of the judging panel will be from the Sakai core team.

Judging and Prizes

The judging panel will determine the criteria for the contest winners and the distribution of the prize money. We have donations for the prize money of several hundred dollars which will likely be distributed as Amazon gift cards.

Judges will not be eligible for prize money themselves (in case they want to submit, or collaborate on a submission).