-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrand
More file actions
49 lines (35 loc) · 740 Bytes
/
rand
File metadata and controls
49 lines (35 loc) · 740 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/sh
# oxr 2025
# Devuelve un numero aleatorio
#
# \\r rand [minº] maxº
#
#
#
# PASAR A VARIABLE
#
[ $include_ctl ] || . include ; include trip trim
rand(){
local rand=0 t=0 a=0 b=0 c=0 d=0 n=$1 m=$2 l=${#2}
[ $# -gt 0 ] || { infsh ~/code/rand 3 5 ; return ;}
[ $l -eq 0 ] && n=0 m=$1 l=${#m}
read t < /proc/uptime
a=${t##*.} b=${t% *} b=${b#*.}
case $l in
1) trim a -s 1 ;;
2) ;;
3) a=$a$b ; trim a -s 3 ;;
4) a=$a$b ;;
*) trip t '.??'
c=${t% *} d=${t#* } c=$((c*d)) d=${#c} rand=$c
trim rand -s $((l-4))
a=$a$rand$b
;;
esac
trip -p a 0
[ ${#a} -gt 0 ] || a=$((n+((m-n)/2)))
while [ $a -lt $n ] ; do a=$((a+n+1)) ; done
while [ $a -gt $m ] ; do a=$((a-m+n-1)) ; done
echo -n $a
}
[ ${0##*/} != rand ] || rand $@