Stationeers

Stationeers

View Stats:
Lion Llew Mar 21, 2023 @ 4:51am
can anyone help? I want to make a random number generator
I am wondering if there are any simple methods in MIPS to make a random number generator. I can think of ways that involve complex atmospherics and reading pressures, doing math, and getting a number/numbers, but I am hoping that there is a simple way to achieve this.
< >
Showing 1-8 of 8 comments
Maireen Mar 21, 2023 @ 10:37am 
you can code a loop to add numbers internally depending how high you want it to go and a jump code in the middle of that to display that number when a button is pressed
Lion Llew Mar 21, 2023 @ 10:58am 
Originally posted by Maireen:
you can code a loop to add numbers internally depending how high you want it to go and a jump code in the middle of that to display that number when a button is pressed

isn't that a bit predictable? like if you time the press right you would get the same result over again? I am looking for maybe 3 or 4 random true or false results at the press of a button, but totally random every time.

so press d0
s d1 result 1
s d2 result 2

and so on.
c.harrison Mar 21, 2023 @ 4:14pm 
I think C10 programming you may be after:
rand
https://stationeers-wiki.com/MIPS
may be a loop with a few to r0 to r3 then add em?
Ketrix Mar 21, 2023 @ 5:48pm 
Rand seems to give a float value between 0 and 1, but not 0 or 1 itself
Multiplication and addition can move the random value to a desired interval

The Klaxon Speaker has 3 songs on mode 7,8 and 9. The script below plays one at random when a button is pushed. Buttons are quirky and will sometimes be "1" during two ticks, the script solves that problem by using an extra yield instruction.

alias klaxon d0
alias button d1
main:
yield
l r0 button Activate
beqz r0 main
#swap the klaxans on state with a not-gate
l r0 klaxon On
seqz r0 r0
s klaxon On r0
#pick a random song
rand r0
mul r0 r0 3
#trunc r0 r0 #optional, removes decimals
add r0 r0 7
s klaxon Mode r0 #play sound 7, 8 or 9
yield #counters the buttons double activation bug
j main
Lion Llew Mar 22, 2023 @ 6:53am 
Originally posted by c.harrison:
I think C10 programming you may be after:
rand
https://stationeers-wiki.com/MIPS
may be a loop with a few to r0 to r3 then add em?

I missed that, think I should read the list through again! Thanks.
Lion Llew Mar 22, 2023 @ 6:54am 
Originally posted by Ketrix:
Rand seems to give a float value between 0 and 1, but not 0 or 1 itself
Multiplication and addition can move the random value to a desired interval

The Klaxon Speaker has 3 songs on mode 7,8 and 9. The script below plays one at random when a button is pushed. Buttons are quirky and will sometimes be "1" during two ticks, the script solves that problem by using an extra yield instruction.

alias klaxon d0
alias button d1
main:
yield
l r0 button Activate
beqz r0 main
#swap the klaxans on state with a not-gate
l r0 klaxon On
seqz r0 r0
s klaxon On r0
#pick a random song
rand r0
mul r0 r0 3
#trunc r0 r0 #optional, removes decimals
add r0 r0 7
s klaxon Mode r0 #play sound 7, 8 or 9
yield #counters the buttons double activation bug
j main

That's awesome! Thank you. I might just use that in my habitat section... when I build it, lol.
LittleShade Mar 22, 2023 @ 6:56am 
define Digit_Numer 100000000#a limited number of digits
Start:
yield
rand r0
mul r1 r0 Digit_Numer
trunc r1 r1
j Start

If you don't specify enough numbers of digits, the same number will likely occur.
Last edited by LittleShade; Mar 22, 2023 @ 7:00am
evilshroud Mar 28, 2023 @ 12:15pm 
Originally posted by pippin2006:
define Digit_Numer 100000000#a limited number of digits
Start:
yield
rand r0
mul r1 r0 Digit_Numer
trunc r1 r1
j Start

If you don't specify enough numbers of digits, the same number will likely occur.


Originally posted by Ketrix:
Rand seems to give a float value between 0 and 1, but not 0 or 1 itself
Multiplication and addition can move the random value to a desired interval

The Klaxon Speaker has 3 songs on mode 7,8 and 9. The script below plays one at random when a button is pushed. Buttons are quirky and will sometimes be "1" during two ticks, the script solves that problem by using an extra yield instruction.

alias klaxon d0
alias button d1
main:
yield
l r0 button Activate
beqz r0 main
#swap the klaxans on state with a not-gate
l r0 klaxon On
seqz r0 r0
s klaxon On r0
#pick a random song
rand r0
mul r0 r0 3
#trunc r0 r0 #optional, removes decimals
add r0 r0 7
s klaxon Mode r0 #play sound 7, 8 or 9
yield #counters the buttons double activation bug
j main
Expanding on these, you could use pippin2006's original multiplier (I'll say 10000, since Lion said maybe 4 true/false results and this will give 4 numbers) idea, makes sure the random number doesn't make it 5 digits (I saw somewhere said "inclusive" but it may be wrong, check and possibly subtract 1 if needed, just to make sure), but then take each digit using a modulus (10,100,1000,10000), then divide by 10/100/1000/10000, round to get either 0 or 1 each, then yield again at the end for Ketrix's button bug fix. Also, you don't have to truncate the number, but you may if you want to.

alias Button d0 define Digit_Number 10000 Start: yield l r0 Button Activate #Check for active button beqz r0 Start #else go back and keep checking rand r0 mul r0 r0 Digit_Number breq r0 10000 2 #Makes sure the number is not 10000 sub r0 r0 1 #to prevent having 5 numbers #Optional: #trunc r0 r0 mod r1 r0 10000 #1st place div r1 r1 10000 round r1 r1 mod r2 r0 1000 #2nd place div r2 r2 1000 round r2 r2 mod r3 r0 100 #3rd place div r3 r3 100 round r3 r3 mod r4 r0 10 #4th place div r4 r4 10 round r4 r4 #set devices on/off (example) based on random s d1 On r1 s d2 On r2 s d3 On r3 s d4 On r4 yield #Counter button double-activation problem j Start
I can't take all the credit for this idea. CowsAreEvil helped me understand this type of digit encoding/decoding. I just took the idea and ran a bit with it. Also, apologies if I used/typed anything incorrectly, I don't have the time right now for testing that out.
Last edited by evilshroud; Mar 28, 2023 @ 12:21pm
< >
Showing 1-8 of 8 comments
Per page: 1530 50

Date Posted: Mar 21, 2023 @ 4:51am
Posts: 8