Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8433929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:31:15+00:00 2026-06-10T06:31:15+00:00

In a unit test I start a helper function (generating test data) with: set.seed(1)

  • 0

In a unit test I start a helper function (generating test data) with:

set.seed(1)

I was developing the unit test interactively like this:

source('tests/runit.functions.R');test.something()

But then when I went to run the tests from my run_tests.R they failed. I narrowed it down to different random numbers, despite the set.seed(1) command! I added this line, just after set.seed(1):

print(sessionInfo());print("RANDOM SEED:");print(.Random.seed)

The really interesting part is the random seed is entirely different. In the batch script it is just three numbers:

501 1280795612 -169270483

Whereas in my interactive R session it is a 626-element monster:

[1]         403         624  -169270483  -442010614 ...
 ...
[617]   197184543    -2095148  ... -689249108

The first number, the 501 vs. 403, is the type of random number generator, apparently, but I couldn’t track down the master list for what the numbers mean.

I think the core of my question is what is the best way to make sure my unit tests have reliable random number generation? A secondary question is troubleshooting advice: how do I track down which random number generator is being used (and more importantly) which code/package/setting decided to use that?

The sessionInfo is not looking very helpful, but it is showing some small differences. E.g. the inclusion of the TTR package is due to other unit tests being run. Here is sessionInfo output from the batch script, where the first line is #!/usr/bin/Rscript --slave:

R version 2.15.1 (2012-06-22)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.utf8       LC_NUMERIC=C              LC_TIME=en_US.utf8        LC_COLLATE=en_US.utf8     LC_MONETARY=en_US.utf8    LC_MESSAGES=en_US.utf8   
 [7] LC_PAPER=C                LC_NAME=C                 LC_ADDRESS=C              LC_TELEPHONE=C            LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C      

attached base packages:
[1] methods   stats     graphics  grDevices utils     datasets  base     

other attached packages:
[1] TTR_0.21-1   xts_0.8-6    zoo_1.7-7    RUnit_0.4.26

loaded via a namespace (and not attached):
[1] grid_2.15.1    lattice_0.20-6

And here is the output from my interactive R session, which is started from the commandline with R --no-save:

R version 2.15.1 (2012-06-22)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.utf8       LC_NUMERIC=C              LC_TIME=en_US.utf8        LC_COLLATE=en_US.utf8     LC_MONETARY=en_US.utf8    LC_MESSAGES=en_US.utf8   
 [7] LC_PAPER=C                LC_NAME=C                 LC_ADDRESS=C              LC_TELEPHONE=C            LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C      

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] xts_0.8-6    zoo_1.7-7    RUnit_0.4.26

loaded via a namespace (and not attached):
[1] grid_2.15.1    lattice_0.20-6 tools_2.15.1  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:31:16+00:00Added an answer on June 10, 2026 at 6:31 am

    It seems you are using the RUnit package for your unit tests. In this case, you need to be aware that RUnit uses a different default for the kind of random number generator (RNGkind).

    From the RUnit manual, and the help for ?defineTestSuite:

    defineTestSuite(name, dirs, testFileRegexp = "^runit.+\\.[rR]$",
      testFuncRegexp = "^test.+",  
      rngKind = "Marsaglia-Multicarry",
      rngNormalKind = "Kinderman-Ramage")
    

    Notice that the default rngKind in RUnit is “Marsaglia-Multicarry”.

    However, in base R, the default RNGkind is “Mersenne-Twister”. From ?RNGkind:

    The currently available RNG kinds are given below. kind is partially
    matched to this list. The default is “Mersenne-Twister”.


    So, to match your interactive results with the results of RUnit, you need to set a different RNGkind, either in your interactive session or in your initial call to defineTestSuite.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a VS2010 unit test project set to using SpecFlow 1.8.1 and mstest.
We start use C# build-in unit test functionality. I have VisualStudio 2008 created unit
Let's say I want to make a Unit-Test where I have this Tetris game
I'd like to be able to run the entire unit-test testSuite in 5 times
Let me start from definition: Unit Test is a software verification and validation method
I'll start by saying I am pretty new to unit testing and I'd like
Visual studio unit testing starts all tests when I use Start Debugging from Debug
Are there too many asserts in this one unit test? [Fact] public void Send_sends_an_email_message()
I'm currently trying to get a unit test set up for an HttpServlet class
Should I start a new project for my unit tests? That would mean that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.