图形随机发生器


10

是否有用于Linux的具有良好GUI的随机生成器,它可以生成两个整数之间的随机整数,并以大字体显示它?


你要做什么?心理数学?
BigSack 2012年

Answers:


36

我不知道任何软件。Google也没有提出任何建议。猜猜这太简单了。如果使用脚本语言编写,则大约应包含30行代码。您也可以创建一个LibreOffice电子表格来做到这一点。应该不是很难。

编辑1:

伪随机数生成器-perl gui脚本

以下是我编写的快速而肮脏的perl脚本。您应该可以自己修改它。当您使用来运行它perl nameOfTheScript.pl或使其成为可执行文件,chmod u+x nameOfTheScript.pl然后双击它时,它将如上图所示。

#!/usr/bin/perl
# © 2011 con-f-use@gmx.net. Use permitted under MIT license: http://www.opensource.org/licenses/mit-license.php
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; });
$window->set_border_width(10);
$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;

编辑2

ObsessiveFOSS要求我包括另一个随机数生成器(因为该脚本使用Perl的内置函数)。在我的其他答案中,您可以看到有关操作方法的草图。


9
+1-您足够关心编写脚本来做到这一点的事实真是太了不起了。
jrg 2011年

4
很高兴看到您花了一些时间为此提供了脚本。大!
samarasa

很高兴你喜欢它。
con-f-use,

@ con-f-use如果可以在gpl许可证中释放它,那就太好了。
Lincity

@Alaukik MIT许可证也可以吗?它更宽松并且与GPL兼容吗?
混淆使用

4

ObsessiveFOSS要求实施Blum等。密码安全的伪随机数生成器。这是我的素描方法。其他代码与我先前的答案相同。只需替换randomizeLabel子例程并插入以下代码即可

use bigint;

# Kinda large primes
$p = 338047573;   # Any pair of large primes will suffice here...
$q = 4182249941;  #+...as 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; });
    $dialog->run;
}

# 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>" );
}

如前所述,它是不完整的。人们将不得不使用按位运算符来提取有用的随机数,对其进行移位和缩放以适合$min$max。现在,最小和最大输入尚未使用。


我怀疑有一个CSPRNG的Perl模块比我的脚本做得更好。
con-f-use

1

如今,使用QML可以非常轻松地完成此操作:

import QtQuick 2.0
import Ubuntu.Components 0.1

Rectangle {
    id: mainView
    width: units.gu(30) 
    height: units.gu(40)
    Column {
        id: generator
        spacing: units.gu(1)
        anchors.horizontalCenter: mainView.horizontalCenter
        Text {
            id: ramdom_number
            text: "0"
            font.pointSize: 100
            anchors.horizontalCenter: generator.horizontalCenter
        }
        TextField {
            id:min
            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);
        }
    }
}

使用以下代码运行此代码qmlscene

在此处输入图片说明

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.