JAVA CODE

//Ex12_6 program
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class Ex12_6 extends Applet implements ActionListener
{
   private Button RndBtn;
   float r;

   public void init()
   {
      RndBtn = new Button ("Random number");
      RndBtn.addActionListener (this);
      add (RndBtn);
   }

   public void paint (Graphics g)
   {
      g.drawString (r + "", 40, 50);
   }

   public void actionPerformed (ActionEvent e)
   {
      r = (float) Math.random();
      repaint();
   }
}