‘I wish you bad luck,” said the chief justice of the United States.

He meant for those words, delivered last spring, to express encouragement and optimism.

The year now ending has been filled with a ceaseless cascade of ugly, angry verbiage aimed in every possible direction.

Yet as 2017 concludes and men and women make hopeful resolutions for 2018, at least one set of words this year offered a universal lesson about the value to be found in generosity of spirit. It came from Chief Justice John Roberts. It wasn’t a Supreme Court ruling or a dissenting opinion, but a quiet message that, amid the cacophony of each day’s seemingly urgent news, deserves to endure.

The chief justice had been invited to present the commencement address at his son’s ninth-grade graduation. The ceremony was, by design, modestly attended.

He told his audience that commencement speakers will typically “wish you good luck and extend good wishes to you. I will not do that, and I’ll tell you why.

“From time to time in the years to come, I hope you will be treated unfairly, so that you will come to know the value of justice.

“I hope that you will suffer betrayal, because that will teach you the importance of loyalty.

“Sorry to say, but I hope you will be lonely from time to time so that you don’t take friends for granted.

“I wish you bad luck, again, from time to time so that you will be conscious of the role of chance in life, and understand that your success is not completely deserved and that the failure of others is not completely deserved either.

“And when you lose, as you will from time to time, I hope every now and then your opponent will gloat over your failure. It is a way for you to understand the importance of sportsmanship.

“I hope you’ll be ignored so that you know the importance of listening to others, and I hope you will have just enough pain to learn compassion.

“Whether I wish these things or not, they’re going to happen. And whether you benefit from them or not will depend upon your ability to see the message in your misfortunes.”

It is difficult to imagine that a person who rises to the position of chief justice of the United States has had a lot of bad luck and betrayal in his life. But those words had to have come from somewhere; through the court, I asked Chief Justice Roberts if he’d care to share the genesis of his speech. Were these thoughts that he’d been carrying around for a long time? Phrases that he had been taught by a parent or grandparent?

He responded that he had prepared the advice specifically for that commencement address, as he set out to reflect upon “some of the harsh realities that everyone will face in the course of a full life,” and how to anticipate them and learn from them.

There was something else that he proposed in the speech, something seemingly simple that bears consideration as 2018 waits just ahead:

“Once a week, you should write a note to someone. Not an email. A note on a piece of paper. It will take you exactly 10 minutes.” Then, he urged, put the note in an envelope and send it off the old way: via U.S. mail.

The handwritten note, he said, might express appreciation for someone who has helped you out or treated you with kindness, and who may not know how grateful you are.

If you do that once a week for, say, 10 months, “40 people will feel a little more special because you did, and they will think you are very special because of what you did.”

Not a bad suggestion, for any of us. I wondered if Chief Justice Roberts manages to write those weekly letters of thanks. He replied that he tries to follow his own advice, “mindful that advice is one of those things that is easier to give than receive.”

So, as the year draws to a close, here’s a toast to bad luck, and to its hidden gifts. First, though, the corner mailbox awaits. Gratitude is priceless, but conveying it costs no more than a postage stamp.