private Link generateRandomizedGameLink(EntityManager em, Player player) {
		Link outputLink = new Link("", "");
		ArrayList<Long> friendIDs = player.getFriendList();

		// You need at least 5 friends to play and generate a valid link
		if (friendIDs.size() <= 4) {
			outputLink.setHref("index.html");
			outputLink
					.setOnClickMethod("(function (){alert('You do not have enough friends to play the game.');return false;});");
			em.persist(outputLink);
			return outputLink;
		}

		Random randomGenerator = new Random();
		ArrayList<Long> randomFriendIDs = new ArrayList<Long>();
		ArrayList<User> friendUsers = new ArrayList<User>();

		// Get 5 friendIDs from the list at random
		for (int index = 0; index <= 4; ++index) {

			// Grab a random integer from 0 to [friendIDs.size() - 1]
			int randomInt = randomGenerator.nextInt(friendIDs.size());

			// Use randomInt as the index in the friendIDs list as the next
			// friend to use
			// Make sure that friend hasn't been used in the link already
			// though.
			if (randomFriendIDs.contains(friendIDs.get(randomInt))) {
				index--; // Repick this gameLink index, the friend's been used
				// already
			} else {
				randomFriendIDs.add(friendIDs.get(randomInt));
				friendUsers.add(getUserByFacebookID(em,
						friendIDs.get(randomInt)));
			}
		}

		// Now that we have the 5 friends to use, we'll display the images of
		// the first 3
		ArrayList<Long> friendImageIDs = new ArrayList<Long>();
		friendImageIDs.add(randomFriendIDs.get(0));
		friendImageIDs.add(randomFriendIDs.get(1));
		friendImageIDs.add(randomFriendIDs.get(2));

		// And re-randomize all 5 names to display at the top to make this a
		// game
		Collections.shuffle(friendUsers);
		ArrayList<String> friendUserNames = new ArrayList<String>();
		friendUserNames.add(friendUsers.get(0).getName());
		friendUserNames.add(friendUsers.get(1).getName());
		friendUserNames.add(friendUsers.get(2).getName());
		friendUserNames.add(friendUsers.get(3).getName());
		friendUserNames.add(friendUsers.get(4).getName());

		outputLink.setHref("playGame.html?playerID="
				+ player.getPlayerInfo().getFacebookID() + "&playerName="
				+ player.getPlayerInfo().getName() + "&playerPoints="
				+ player.getPoints() + "&friendIDList="
				+ printList(friendImageIDs) + "&friendNameList="
				+ printList(friendUserNames));
		em.persist(outputLink);
		em.flush();
		return outputLink;
	}