Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a random generator for linux with a nice GUI, which can generate a random integer between two integers and display it with a large fontsize?

share|improve this question
What you gonna do? Mental Maths? – BigSack Aug 21 '12 at 13:58
up vote 36 down vote accepted

I don't know any software. Google didn't come up with something either. Guess this is too simple a problem. It should be about 30 lines of code if you wrote it in a scripting language. You could also create a LibreOffice spreadsheet to do that. Shouldn't be terribly difficult.

Edit 1:

pseudo-random number generator - perl gui script

Below is a quick and dirty perl script I coded. You should be able to modify it yourself. When you run it with perl or make it executable with chmod u+x and then double click it, it will look like in the picture above.

# © 2011 Use permitted under MIT license:
use Gtk2 '-init'; # relies on the gnome toolkit bindings for perl

$size = 1e5;   # fontsize in 0.001 pt (only god knows why)

sub randomizeLabel {   #### this does the actual randomisation
    $min = int($entry1->get_text);
    $max = int($entry2->get_text);
    $rand = int(rand($max-$min+1)) + $min;
    $diplabel->set_markup( "<span size=\"$size\">$rand</span>" );
#### the rest is gui stuff:
$window = Gtk2::Window->new('toplevel');
$window->set_title('Random Integer Generator');
$window->signal_connect(destroy => sub { Gtk2->main_quit; });
$window->signal_connect(delete_event => sub { Gtk2->main_quit; });
$vbox = Gtk2::VBox->new(0, 5);   $window->add($vbox); $vbox->show;

$diplabel = Gtk2::Label->new;
$diplabel->set_markup("<span size=\"$size\">0</span>");
$vbox->add($diplabel);          $diplabel->show;

$entry1 = Gtk2::Entry->new;     $vbox->add($entry1);    $entry1->show;
$entry2 = Gtk2::Entry->new;     $vbox->add($entry2);    $entry2->show;

$button = Gtk2::Button->new("Generate!");
$button->signal_connect(clicked => \&randomizeLabel, $window);
$vbox->add($button);            $button->show;

$window->show;    Gtk2->main;
exit 0;


ObsessiveFOSS asked me to include another generator for random numbers (as it is this script uses Perl's build-in one). You can see a sketch on howto do it in my other answer.

share|improve this answer
Thanks for the script, it's very nice!!! – student May 29 '11 at 19:45
+1 - the fact you cared enough to write a script to do that is amazing. – James May 29 '11 at 20:33
It is nice to see that you spent time on providing a script for this. Great! – samarasa May 30 '11 at 6:47
Glad you like it. – con-f-use May 30 '11 at 8:55
@con-f-use it would be nice if you could release it in the gpl license . – Alaukik Jun 1 '11 at 11:28

ObsessiveFOSS asked to implement the Blum, et al. cryptographically secure pseudo-random number generator. Here is my sketch on how to do it. The other code stays the same as in my earlier answer. One just has to replace the randomizeLabel subroutine and insert this code instead:

use bigint;

# Kinda large primes
$p = 338047573;   # Any pair of large primes will suffice here...
$q = 4182249941; long as they fullfill the congruence check below
$rand = 7;    # Seed for the random number generator (x_0 in the wiki)

sub errMsg {
    $dialog = Gtk2::MessageDialog->new($window, 'destroy-with-parent', 'error', 'ok', $_[0]);
    $dialog->signal_connect (response => sub { exit 1; });

# Check congruence 3 mod 4 (for quadratic residue)
if( ($p-3)%4 == 0 ) { errMsg('Error: Variable p is ill choosen.'); }
if( ($q-3)%4 == 0 ) { errMsg('Error: Variable q is ill choosen.'); }
# Note: For large cycle lengths gcd(φ(p-1), φ(q-1)) should also be small,...
#+...where φ is Euler's totient function but this is not checked here

# Compute Modulus in Blum Blum Shub
$M = $p*$q;

sub randomizeLabel { # This does the actual randomization
    $min = int($entry1->get_text); $max = int($entry2->get_text); # Boundaries for the desired random range from the input filed of the GUI (included for convenience when modifying the script - not used here)

    # Blum Blum Shub pseudo random number generator
    $rand = ($rand*$rand) % $M;

    # Here you have to extract the bits and shift them in range
    $randout = $rand & (2**6-1); # Change this line. It's an example and extracts the five least significant bits! To extract the ten LSBs use '(2**11-1)' and so on...
    # $randout = ...$min...$max...; # shift it in the right range (not done here)

    $diplabel->set_markup( "<span size=\"$size\">$randout</span>" );

As mentioned it is incomplete. One would have to use bitwise operators to extract useful random numbers, shift and scale them to fit between $min and $max. Right now the input for minimum and maximum is unused.

share|improve this answer
I suspect there is a Perl module for CSPRNG that does a better job than my script. – con-f-use Aug 30 '12 at 15:43

It can be done very easily with QML today:

import QtQuick 2.0
import Ubuntu.Components 0.1

Rectangle {
    id: mainView
    Column {
        id: generator
        anchors.horizontalCenter: mainView.horizontalCenter
        Text {
            id: ramdom_number
            text: "0"
            font.pointSize: 100
            anchors.horizontalCenter: generator.horizontalCenter
        TextField {
            text: "0"
        TextField {
            id: max
            text: "100"
        Button {
            text: "Generate!"
            width: generator.width
            onClicked: ramdom_number.text = Math.floor((Math.random()*(max.text-min.text+1))+min.text);

Run this code with qmlscene:

enter image description here

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.