[Solved] Craps simulator question

Discuss the spreadsheet application
Post Reply
thamptondmd
Posts: 3
Joined: Mon Aug 23, 2021 4:31 am

[Solved] Craps simulator question

Post by thamptondmd »

Is it possible to save the value in a cell before it changes from the randomizer?
I have made a craps simulator. It can roll the dice, establish the point, turn the button on and off, and declare a win or loss based on hitting the point or a rolling a seven. The simulator will then start over and establish a new point and continue on. The problem comes in when adding or reducing the bankroll. The simulator will tell me how many times each number was hit during the roll (say 3 9's or 2 11's) and if there is a 7 out, it's simple. But when there is a point/"win" I run into the problem. In a regular game of craps, the number of hits on each number would increase after a win in the new roll until the 7 out. Because the simulation is starting over after the point is hit, the number of recorded hits is being erased and total number of hits cannot be counted. If there was a way to 'record' the value (like a M+ button on a calculator) I could move on with finishing the project. Any ideas or solutions? I am reading on here something about macros but I know nothing about the subject and am not sure if that would be a possible solution. Any help would be appreciated.
Last edited by MrProgrammer on Wed Sep 08, 2021 6:50 am, edited 1 time in total.
Reason: Tagged ✓ [Solved]
Open Office 4.1.3
Windows 10
User avatar
robleyd
Moderator
Posts: 5082
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: craps simulator question

Post by robleyd »

Perhaps Lupp's response in A code to store a previous cell value[ might give you some ideas.
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
thamptondmd
Posts: 3
Joined: Mon Aug 23, 2021 4:31 am

Re: craps simulator question

Post by thamptondmd »

Thank you, lot of info in there. I can see that I might need to figure another way around this problem.
Open Office 4.1.3
Windows 10
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: craps simulator question

Post by John_Ha »

Say 17 is displayed as the random number in A1.

r-click > Copy.
r-click in A3 > Paste Special > Number ..., pastes 17 in A3 but, as this changes the sheet, the random number in A1 is recalculated to, say, 23.

It works copying multiple cells.
random.ods
(9.47 KiB) Downloaded 112 times
LibreOffice 7.0 and later has a non-volatile RAND.NV
RAND.NV

Syntax RAND.NV()

This function produces a non-volatile random number on input. A non-volatile function is not recalculated at new input events. The function does not recalculate when pressing F9, except when the cursor is on the cell containing the function. The function is recalculated when opening the file.

Example

=RAND.NV() returns a non-volatile random number between 0 and 1.

RANDBETWEEN

Returns an integer random number in a specified range.
Syntax RANDBETWEEN(Bottom; Top)

Returns an integer random number between integers Bottom and Top (both inclusive).

This function produces a new random number each time Calc recalculates. To force Calc to recalculate manually press F9.

To generate random numbers which never recalculate, copy cells containing this function and use Edit - Paste Special (with Paste All and Formulae not marked and Numbers marked).

Example

=RANDBETWEEN(20;30) returns an integer in the range 20 to 30.
Last edited by John_Ha on Tue Aug 24, 2021 11:26 am, edited 3 times in total.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
User avatar
Lupp
Volunteer
Posts: 3549
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: craps simulator question

Post by Lupp »

I sent a PM to "thamptondmd".

My post to the thread "robleyd" linked to above is nearly 6 years old now. Meanwile my attitude witrh respect to the attempted solution by "ConditionallySuspendedCircularReferences" is dissuasive due to doubts concerning the reliability. The high complexity and the high amount of addtionally needed development for adaptions to variant cases also must be taken in account.

Transaction tracking using an established DB system should be the means of choice, but I'm not sufficiently informed to go into details.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
thamptondmd
Posts: 3
Joined: Mon Aug 23, 2021 4:31 am

Re: craps simulator question

Post by thamptondmd »

Thank you for the note Lupp. Sorry for bringing up old ghosts. The copy/paste special works exactly as I need John. It even has an add function which is what I am looking for. Is there anyway to have this automatically run when I hit the f9 button?
Open Office 4.1.3
Windows 10
User avatar
MrProgrammer
Moderator
Posts: 4905
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: Craps simulator question

Post by MrProgrammer »

thamptondmd wrote:Is there anyway to have this automatically run when I hit the f9 button?
Record a macro to perform Paste Special → Add. Choose a keyboard shortcut other than F9, since Calc uses that one.
[Tutorial] Favorite Recorded Calc Macros

If this solved your problem please go to your first post use the Edit button and add [Solved] to the start of the subject field. Select the green checkmark icon at the same time.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.6.3, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
Post Reply