Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

generating random thruth-tables

by neniro (Priest)
on Sep 24, 2008 at 13:34 UTC ( #713422=snippet: print w/ replies, xml ) Need Help??

Description: I needed a bunch of truth-tables, with random result-rows, as exercises for logical minimization. An easy task utilizing Perl:
perl -e "print sprintf('%03b',$_).' '.int(rand()+0.5).$/ for 0..7"
Comment on generating random thruth-tables
Download Code
Replies are listed 'Best First'.
Re: generating random thruth-tables
by toolic (Bishop) on Sep 24, 2008 at 14:06 UTC
    Really no need for both print and sprintf when just printf will suffice. And while I'm at it, I'll just reach into my (perl) golf bag and club your code down some:
    perl -e'printf"%03b %b\n",$_,rand(2)for 0..7'

      You can chop one character off like perl -e'printf"%03b %b\n",$_,rand 2for 0..7'.

      I really like this - it's shorter and easier to read!

Back to Snippets Section

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://713422]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2015-09-02 07:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred temperature scale is:










    Results (64 votes), past polls