This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Mr_Programmer's profile picture

[Resolved] Random Number Rednet Confimation

Started by Mr_Programmer, 25 June 2017 - 10:44 PM
Mr_Programmer #1
Posted 26 June 2017 - 12:44 AM
Hey guys

Im working on a project where i want to sync a server to a client but as a secure feature i want to use a Sync code generated by the server that the client then has to input, from here it is sent to the server ID and compair however never seams to work

never really used the math.random so i have no clue :lol:/>

the code i have set up atm is for testing purposes, could someone tell me where im going wrong?

Thanks, MrProgrammer

randomCodeGen = math.random(100000000,999999999)
print(randomCodeGen)

syncLoop = true
while syncLoop == true do
local event, syncCode, ID = os.pullEventRaw()
  if event == "rednet_message" then
	if syncCode == randomCodeGen then
	  os.reboot()
	else
	  os.shutdown()
	end
  end
end

What i think is happening is when im calling the randomCodeGen its Gening one number then when i call it the second time its Gening a new number but how do i stop this?
Edited on 25 June 2017 - 11:24 PM
KingofGamesYami #2
Posted 26 June 2017 - 12:50 AM
Well, you never call randomCodeGen as it isn't a function so that's definitely not happening.

You only call math.random once, so it will only generate one random number.

I have literally no idea how your code is supposed to work, nor what it is doing instead, so I can't really help beyond this.
Mr_Programmer #3
Posted 26 June 2017 - 12:52 AM
Well, you never call randomCodeGen as it isn't a function so that's definitely not happening.

You only call math.random once, so it will only generate one random number.

I have literally no idea how your code is supposed to work, nor what it is doing instead, so I can't really help beyond this.

Long story Short i want to get a random number and keep it so i can compair rednet messages to the number that was generated
KingofGamesYami #4
Posted 26 June 2017 - 01:11 AM
Right, that's exactly what your code is doing. But you wouldn't have created a post if it was doing what you thought it was. So you will have to give me more detail about why you think it is not doing that.
Mr_Programmer #5
Posted 26 June 2017 - 01:16 AM
Right, that's exactly what your code is doing. But you wouldn't have created a post if it was doing what you thought it was. So you will have to give me more detail about why you think it is not doing that.

Ok so i have sorted it, i haven't really used tables before but after abit of reading on the table api i basically inserted the number that was being generated into a table then compaired the rednet message to the table, i also had the syncCode and ID in the wrong place :unsure:/>

At this point it is also where i found out that everything was right and the syncCode and ID was the wrong way round which was making it not do what i wanted it to do
Edited on 25 June 2017 - 11:22 PM