Skip to main content
added 197 characters in body
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372

MATL, 1312 13 14 bytes

r.1H$YlY[ii++1H$YlY[ihs

Input is of the form [3 4], that is, a row vector with the two numbers.

Example

>> matl r.1H$YlY[ihs
> [3 4]
7

Explanation

This generates the geometric random variable without loops, by directly applying a a transformation to a uniform random variable. Note that log0.1 a is used instead of log a / log 0.1 to save 1 byte.

r        % random number with uniform distribution in (0,1)
.1       % number 0.1
H$       % specify two inputs for next function
Yl       % logarithm in specified base (0.1)
Y[       % floor. This produces the geometric random variable with parameter 0.1
i        % input number      vector of two numbers
ih        % inputconcatenate number
+horizontally with the previously generated random value
s  % addition
+     % sum of %vector additionelements

MATL, 13 14 bytes

r.1H$YlY[ii++

This generates the geometric random variable without loops, by directly applying a a transformation to a uniform random variable. Note that log0.1 a is used instead of log a / log 0.1 to save 1 byte.

r        % random number with uniform distribution in (0,1)
.1       % number 0.1
H$       % specify two inputs for next function
Yl       % logarithm in specified base (0.1)
Y[       % floor. This produces the geometric random variable with parameter 0.1
i        % input number         
i        % input number
+        % addition
+        % addition

MATL, 12 13 14 bytes

r.1H$YlY[ihs

Input is of the form [3 4], that is, a row vector with the two numbers.

Example

>> matl r.1H$YlY[ihs
> [3 4]
7

Explanation

This generates the geometric random variable without loops, by directly applying a a transformation to a uniform random variable. Note that log0.1 a is used instead of log a / log 0.1 to save 1 byte.

r        % random number with uniform distribution in (0,1)
.1       % number 0.1
H$       % specify two inputs for next function
Yl       % logarithm in specified base (0.1)
Y[       % floor. This produces the geometric random variable with parameter 0.1
i        % input vector of two numbers
h        % concatenate horizontally with the previously generated random value
s        % sum of vector elements
added 119 characters in body
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372

MATL, 1413 14 bytes

rYlr.1Yl/Y[ii++1H$YlY[ii++

This generates the geometric random variable without loops, by directly applying a a transformation to a a uniform random variable. Note that log0.1 a is used instead of log a / log 0.1 to save 1 byte.

r        % random number with uniform distribution in (0,1)
Yl.1      % logarithm% number 
 0.1  
H$    % number literal
Yl % specify two inputs for %next logarithmfunction
Yl    
/   % logarithm in specified %base division(0.1)
Y[       % floor. This produces the geometric random variable with parameter 0.1
i        % input number         
i        % input number
+        % addition
+        % addition

MATL, 14 bytes

rYl.1Yl/Y[ii++

This generates the geometric random variable without loops, by directly applying a a transformation to a uniform random variable.

r       % random number with uniform distribution in (0,1)
Yl      % logarithm  
 .1      % number literal
Yl      % logarithm    
/       % division
Y[      % floor. This produces the geometric random variable with parameter 0.1
i       % input number         
i       % input number
+       % addition
+       % addition

MATL, 13 14 bytes

r.1H$YlY[ii++

This generates the geometric random variable without loops, by directly applying a a transformation to a uniform random variable. Note that log0.1 a is used instead of log a / log 0.1 to save 1 byte.

r        % random number with uniform distribution in (0,1)
.1       % number 0.1
H$       % specify two inputs for next function
Yl       % logarithm in specified base (0.1)
Y[       % floor. This produces the geometric random variable with parameter 0.1
i        % input number         
i        % input number
+        % addition
+        % addition
edited body
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372

MATL, 14 bytes

rYl.1Yl/Y[ii++

This generates the geometric random variable without loops, by directly applying a a transformation to a uniform random variable.

r       % random number with uniform distribution in (0,1)
Yl      % logarithm  
.1      % number literaliteral
Yl      % logarithm    
/       % division.
Y[      % floor. This givesproduces the geometric random variable with parameter 0.1
i       % input number         
+i       % additioninput number
i+       % input numberaddition
+       % addition

MATL, 14 bytes

rYl.1Yl/Y[ii++

This generates the geometric random variable without loops, by directly applying a a transformation to a uniform random variable.

r       % random number with uniform distribution in (0,1)
Yl      % logarithm  
.1      % number litera
Yl      % logarithm    
/       % division.
Y[      % floor. This gives the geometric random variable
i       % input number         
+       % addition
i       % input number
+       % addition

MATL, 14 bytes

rYl.1Yl/Y[ii++

This generates the geometric random variable without loops, by directly applying a a transformation to a uniform random variable.

r       % random number with uniform distribution in (0,1)
Yl      % logarithm  
.1      % number literal
Yl      % logarithm    
/       % division
Y[      % floor. This produces the geometric random variable with parameter 0.1
i       % input number         
i       % input number
+       % addition
+       % addition
Source Link
Luis Mendo
  • 105.3k
  • 9
  • 135
  • 372
Loading