Wireless sensor networks (WSNs) are receiving significant attention. In which, there is a large number of studies are being done to address the problem of clock synchronization; where an adversary attacks a node and it can prevent the network from running certain clock-based applications. Due to the low capacity of wireless sensors, we propose in this article a new technique to synchronize the nodes of a system, through the random selection of a subset of neighbors instead of taking into account all the neighbors. Thanks to the proposed technique, we reduce the influence of malicious nodes, reduce the storage space, computation time, and energy consumption.