Cannot access variables within a widget

This is more of a pure PHP than WordPress.

  1. You are implicitly creating $ranNum as local variable in function scope.
  2. $Example_Widget won’t access widget instance in PHP.

What you should be using is $this->ranNum, for reading and writing. That will create object’s property implicitly, but you likely should declare it explicitly in your class definition (see PHP docs on properties).