TI-84 random number generation on a computer

[亡魂溺海] 提交于 2019-12-11 08:24:25

问题


How does the TI-84 randInt function generate random numbers? I would like to replicate this PRNG on my computer so I can get some larger sample sizes, but I'm not sure how. Copying numbers 5 at a time from the calculator isn't an option. Running OS X 10.7.3


回答1:


I don't know of how to exactly replicate its function on a computer, however you do not have to generate only five numbers at a time. You can store very large random number samples in lists them transfer them via the ti connect software to your computer.




回答2:


Based on my much more extensive answer here, the following is a C++ implementation of the Ti PRNG:

#include <iostream>
#include <iomanip>
using namespace std;

long mod1  = 2147483563;
long mod2  = 2147483399;
long mult1 = 40014;
long mult2 = 40692;
long seed1,seed2;

void Seed(int n){
  if(n<0) //Perform an abs
    n = -n;
  if(n==0){
    seed1 = 12345;
    seed2 = 67890;
  } else {
    seed1 = (mult1*n)%mod1;
    seed2 = n%mod2;
  }
}

double Uniform(){
  double result;
  seed1  = (seed1*mult1)%mod1;
  seed2  = (seed2*mult2)%mod2;
  result = (double)(seed1-seed2)/(double)mod1;
  if(result<0)
    result = result+1;
  return result;
}

double RandInt(int min, int max){
  if(min<max)
    return min+int((max-min+1)*Uniform());
  else
    return max+int((min-max+1)*Uniform());
}

int main(){
  Seed(0);
  for(int i=0;i<10;i++)
    cout<<setprecision(10)<<RandInt(5,97)<<endl;
}

I used a Ti-83 emulator to generate values for RandInt(5,97):

This matches the output of my program above:

$ ./a.out 
92
89
18
52
42
73
9
36
97
23


来源:https://stackoverflow.com/questions/10122841/ti-84-random-number-generation-on-a-computer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!