File: random.pir

package info (click to toggle)
parrot 2.0.0-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 23,156 kB
  • ctags: 14,972
  • sloc: perl: 96,188; ansic: 88,708; yacc: 4,923; lex: 4,254; lisp: 1,163; cpp: 746; python: 541; ruby: 351; makefile: 184; sh: 146; cs: 49; asm: 30
file content (52 lines) | stat: -rw-r--r-- 779 bytes parent folder | download
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
50
51
52
#!./parrot -R cgp
# Copyright (C) 2005-2009, Parrot Foundation.
# $Id$
#
# random.pir N         (N = 900000 for shootout)
# by Joshua Isom

.sub main :main
	.param pmc argv
	$S0 = argv[1]
	$I0 = $S0
while_1:
	gen_random(100.0)
	dec $I0
	if $I0 > 1 goto while_1
	$N0 = gen_random(100.0)
	$P0 = new 'FixedFloatArray'
	$P0 = 1
	$P0[0] = $N0
	$S0 = sprintf "%.9f\n", $P0
	print $S0
	.return(0)
.end

.const num IM = 139968.0
.const num IA = 3877.0
.const num IC = 29573.0

.sub gen_random
	.param num max
	.local num last
	last = 42.0
loop:
	$N0 = last
	$N0 *= IA
	$N0 += IC
	$N0 %= IM
	$N1 = max
	$N1 *= $N0
	$N1 /= IM
	last = $N0
	.yield($N1)
	get_params "0", max
	goto loop
.end


# Local Variables:
#   mode: pir
#   fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: