[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Help - Random predicate
From: |
Detlef Sax |
Subject: |
RE: Help - Random predicate |
Date: |
Thu, 28 Feb 2002 18:58:32 +0100 (CET) |
On 28-Feb-2002 Vidhya Subramanian wrote:
Hi,
> i want to select an element randomly from a given list. i don't know
> how to use the random predicate. can anyone help me?
Maybe. Please have a look at the following code.
word_char/2 is a test if char is within ascii.
If you are on a unix you're able to look at man ascii
for the decimal values of the char codes.
If you're not, you can look in a manual for a older printer
or get ascii codes by using a search engine.
%get_one(+Length, -Password)
get_one(0, []) :- !.
get_one(N, [L|Rest]) :-
repeat,
random(48, 122, Rand),
word_char(Rand),
N1 is dec(N),
char_code(L, Rand),
get_one(N1, Rest).
--
http://www.noart.de/
Date: 28-Feb-2002
Time: 18:53:15